General discussion

Locked

using javascript to display xml doc with dtd

By kbowen ·
Hello,

I am able to get the javascript to open the xml document without the dtd. But when I add the dtd in the xml, the javascript will no longer display the xml data. Help!

I have the html/javascript code, the xml file with the list of news articles and then the xml file with dtd.

your comments suggestions,etc....are greatly appreciated.

Thank you,
kim

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<head>
<title>Load Xml Document Demo</title>
<script type=text/javascript>
function CJL_loadXmlDocument(xmlFile, cbFun)
{
var xdoc, xmldoc;

if( window.ActiveXObject && /Win/.test(navigator.userAgent) )
{
xdoc = new ActiveXObject("Microsoft.XMLDOM");
xdoc.async = false;
xdoc.load(xmlFile);
cbFun(xdoc);
return true;
}
else if( document.implementation && document.implementation.createDocument )
{
xdoc = document.implementation.createDocument("", "", null);
xdoc.load(xmlFile);
xdoc.onload = function()
{
cbFun(xdoc);
}
return true;
}
else
{
return false;
}
}
</script>
</head>
<body>
<div id="news">
<script type=text/javascript>
var e = document.getElementById("news");

function writeXMLData(xdoc)
{
var htmltxt = "";
var articles = xdoc.getElementsByTagName("article");
for(var i = 0; i < articles.length; ++i){
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async = false;
xmldoc.load(articles.getAttribute("url"));
// var news = xmldoc.getElementsByTagName("article");
var news = xmldoc.selectNodes("/article");
alert (news);
for(var j = 0; j < news.length; ++j){
htmltxt += news[j].childNodes(0).firstChild.text; // date
htmltxt += "<br>";
htmltxt += news[j].childNodes(1).firstChild.text; //title
htmltxt += "<br>";
htmltxt += news[j].childNodes(2).firstChild.text; //content
htmltxt += "<br><br>";
}
}
e.appendChild(document.createElement("div")).innerHTML = htmltxt;
}

if( ! CJL_loadXmlDocument("news.xml", writeXMLData) )
{
e.appendChild(document.createElement("div")).innerHTML =
"Browser doesn't support external XML loading";
}
</script>
</div>
</body>
</html>

<?xml version="1.0" ?>
<news>
<article url="news_12292003.xml"></article>
</news>

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<article>
<date>12/29/2003</date>
<header>David Neidorf speaks on an "Ecology-Based Ethics" in Fall 2003 Lecture Series</header>
<content>David Neidorf, a former member of the Shimer Faculty (1988-1989), will give the final lecture in the Fall 2003 Lecture Series. He will speak on "The False Dream of an Ecology-Based Ethics". This lecture will take place at 6:30 PM on Tuesday, December 2nd, in the Shimer College Gymnasium.
<br/><br/>
After teaching at Shimer David Neidorf moved to California, where he taught in the Integral Program of Saint Mary's College of California and at Deep Springs College. He is currently director of the Integrated Studies Program at Middlebury College in Vermont, a program that offers team-taught classes that combine perspectives from the sciences and humanities in single classes. He also consults on the development of interdisciplinary programs within traditional undergraduate colleges.
<br/><br/>
This lecture is free of charge and open to the public. It will be followed by a question-and-answer session, and a reception in Prairie House Lounge, adjacent to the Gymnasium. For more information, contact Barbara S. Stone at 847-249-7192 or at .</content>
</article>

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

ingore this ......

by kbowen In reply to using javascript to displ ...

Hello,

I found out was was really going on. I don't need a DTD. I am learning.

The problem really was the htmltxt += news[j].childNodes(2).firstChild.text; //content line not displaying the full text of the <content></content> in the xml file. When I changed it to htmltxt += news[j].childNodes(2).text; //content. It displayed all of it.

But....it doesn't display the <br/> tags in the xml document properly with in the innerhtml of the div tag. I am still researching what can be done to resolve this.

Thank you everyone and sorry for the confusion.

Kim

Collapse -

Re: using javascript to display xml doc with dtd

by ivar.suits In reply to using javascript to displ ...

Hi

This means that your xml is not valid according that dtd. I had the same problem with IE. Just turn validation off and it works.
xmlDoc.validateOnParse = "false"

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums