Srakotraqu
New Member
This is a bit strange. I ran this script in different computer and got different result. In one computer, this code worked but didn't work in another. Here's my js code:\[code\]xmlDoc = loadXmlDoc();printSubClassOf();function loadXmlDoc(){ var xmlDom = null; var xhttp = new XMLHttpRequest(); xhttp.open("GET", "resto.owl", false); xhttp.send(null); xmlDom = xhttp.responseXML; return xmlDom;}function printSubClassOf(){ a = xmlDoc.getElementsByTagName("SubClassOf"); for(i = 0; i < a.length; i++){ b = xmlDoc.getElementsByTagName("SubClassOf").childNodes; for(j = 0; j < b.length; j++){ c = xmlDoc.getElementsByTagName("SubClassOf").childNodes[j]; document.write(i + " " + j + " " + c.nodeName + "<br>"); } }}\[/code\]And this is the XML I tried to parse.\[code\]<Ontology> <SubClassOf> <Class IRI="#Chef"/> <Class IRI="#Employee"/> </SubClassOf> <SubClassOf> <Class IRI="#Customer"/> <Class IRI="#People"/> </SubClassOf></Ontology>\[/code\]I used Chrome Developer Tools to see what was going on. There was a XHR request with 200 status code but still got this error.\[code\]a = xmlDoc.getElementsByTagName("SubClassOf");Uncaught TypeError: Cannot call method 'getElementsByTagName' of null\[/code\]I think \[code\]printSubClassOf()\[/code\] finished before \[code\]loadXmlDoc()\[/code\] returns the XML. What do you think? And how to solve this problem? FYI: I ran this on localhost.