Start New Discussion Reply to this Discussion XML using DOM
I have an XML file that i am parsing using DOM. I dont know why my code is not working.
<html>
<head>
<script type="text/javascript">
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
xhttp=new XMLHttpRequest();
else
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
</script>
</head>
<body style="color:red">
<script type="text/javascript">
xmldoc=loadXMLDoc("food.xml");
document.write(xmldoc.getElementsByTagName("name")[0].childNodes[0].nodeValue);
</script>
</body>
</html>
The following is the "food.xml" file
<?xml version="1.0" encoding="ISO-8859-1"?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>two glasses maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>light Belgian waffles cream</description>
<calories>900</calories>
</food>
</breakfast_menu>
Related Article: xml to xml using xslt
is a solved XML, XSLT and XPATH discussion thread by ibdatx that has 5 replies, was last updated 2 years ago and has been tagged with the keywords: xml, xslt.
vijiraghs
Light Poster
30 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Try this replacement.
<script type="text/javascript">
xmldoc=loadXMLDoc("food.xml");
document.write(xmldoc.childNodes[0].children[0].children[0].childNodes[0].nodeValue);
</script>
Hope this helps.
tinymark
Junior Poster
158 posts since Feb 2010
Reputation Points: 11
Solved Threads: 17
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page rendered in 0.0810 seconds
using 2.69MB