A question on why i am not able to access my XML document.
The first bit of code below is my attempt to grab the data out of the XML document ticker_trial3.xml. It errors out when i run the window saying that passedNode.childNodes is null or does not exist. But i don’t understand since it calls the correct parent ticker but why can it not see the childs?
I ultimately would like to pull the groups of childNodes out separately and then put them on separate rows within a small table. Any help would be apreciated.
–document1.htm–
<html>
<head>
var xmlDoc = new ActiveXObject(“microsoft.xmldom”);
xmlDoc.async=false;
xmlDoc.load(“../ticker_trial3.xml”);
ticker=xmlDoc.documentElement;
newHTML=””;
function start()
{
newHTML+=(“<table border>”);
newHTML+=(“<caption>”);
newHTML+=(“Employee Directory”);
newHTML+=(“</caption>”);
buildTree(“ticker”);
newHTML+=(“</table>”);
document.all.news_ticker.innerHTML=newHTML;
}
function buildTree(passedNode) {
var children = passedNode.childNodes.length;
for (var j=0; j<children; j++) {
Node=passedNode.childNodes.item(j)
if (!Node.hasChildNodes()) {
if (Node.parentNode.nodeName==”date”) {
newHTML+=(“<tr><td>” + Node.text + “</td>”);
}
if (Node.parentNode.nodeName==”name”) {
newHTML+=(“<td>” + Node.text + “</td></tr>”);
}
}
buildTree(Node);
}
}
</script>
</head>
<body>
<span id=news_ticker style=”position:relative;”></span>
</body>
</html>
–ticker_trial3.xml
<?xml version=”1.0″ encoding=”iso-8859-1″?>
<ticker>
<tickeritem URL=”_blank”>
<date>March 18, 2004</date>
<name>Marc</name>
<title>President of this country”</title>
<topic>”Hopefully this works”</topic>
</tickeritem>
<tickeritem URL=”
<date>April 25,2004</date>
<name>Anthony</name>
<title>NEW HTML and XML GURU</title>
<topic>”Atempting this one”</topic>
</tickeritem>
</ticker>
Thanks,
Anthony