I can't figure out how to access the data between the inner nested tags. When I run this javascript, all I see is "Null".
Here is what my xml file named "bboard.xml" looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Designed by Someone -->
<bulletinboard>
<article>
<title lang="en"><h2>eeeeeeeeegg #1</h2></title>
<detail><span class="detail">aaaaapple</span><a href="../data/csr.html#artcl1"> ...more </a></detail>
<date>12/09/09</date>
</article>
</bulletinboard>
Here is the javascript named "loadxmldoc.js":
function loadXMLDoc(dname)
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e) {alert(e.message)}
}
try
{
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}
catch(e) {alert(e.message)}
return(null);
}
And finally, here is the actual HTML page where I want to display the result of javascript. It is called "javdemo.html":
<html>
<head>
<script type="text/javascript" src="loadxmldoc.js">
</script>
</head>
<body>
<div>
<script type="text/javascript">
xmlDoc=loadXMLDoc("bboard.xml");
var x=xmlDoc.getElementsByTagName("title");
var y=xmlDoc.getElementsByTagName("detail");
var z=xmlDoc.getElementsByTagName("date");
document.write("<h4>"+"A Live Bulletin Board"+"</h4>");
for (i=0;i<x.length;i++)
{
document.write("<h1>"+x[i].childNodes[0].nodeValue+"</h1>");
document.write(y[i].childNodes[0].nodeValue);
document.write(z[i].childNodes[0].nodeValue);
document.write("<p>"+" "+"</p>");
// document.write("</div>")
}
</script>
</div>
</body>
</html>
This probably won't show the full code in your browser. By the way how do you escape html tags here on stack overflow?