I have been experimenting with XPath to navigate through my XML document by following examples from W3Schools. However, I am facing an issue where the iterateNext() function returns null every time. Here is a snippet from my blog.xml file:
<blog
xmlns ="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="blogschema.xsd">
<Title>My blog</Title>
<Entry>
<Heading id="101">week1</Heading>
<body>
<text>enter text right here</text>
<pictures>pictures in the body</pictures>
</body>
<labels>Seperate labels with commas</labels>
<date> 20121119</date>
</Entry>
</blog>
Despite referring to W3Schools for guidance, my HTML script seems to be encountering issues as the while statement is never triggered due to the result always being null. It appears that there might be something missing or incorrectly implemented on my end, even though I assumed the provided example should work flawlessly.
xmlDoc = loadXMLDoc("blog.xml"); // loads the XML file
// loadXmlContent(xmlDoc); using XML DOM
path = "/blog/Title";
if (document.implementation && document.implementation.createDocument)
{
var nodes = xmlDoc.evaluate(path, xmlDoc, null, 5, null);
alert(nodes);
var result = nodes.iterateNext();
while (result)
{
document.write(result.childNodes[0].nodeValue);
}
}
</script>