I was testing some code on the tryit editor and was unable to replicate functionality when I save the code locally and was wondering it anyone had any ideas as to why this seems to happen.
The code snippet is
<html>
<head>
<script type="text/javascript" src="http://www.w3schools.com/dom/loadxmldoc.js"></script>
</head>
<body>
<script type="text/javascript">
xmlDoc=loadXMLDoc("http://www.w3schools.com/dom/books.xml");
for (j=0;j<xmlDoc.getElementsByTagName("book").length;j++ )
{
x=xmlDoc.getElementsByTagName("book")[j].childNodes;
y=xmlDoc.getElementsByTagName("book")[j].firstChild;
for (i=0;i<x.length;i++)
{
if (y.nodeType==1)
{
//Process only element nodes (type 1)
document.write(y.nodeName + " : " +x[i].childNodes[0].nodeValue + "<br />");
}
y=y.nextSibling;
}
}
</script>
</body>
</html>
Can someone tell me what I’m doing wrong here
Many thanks in advance
Edit: Thanks to all for the w3schools tip. I think I abuse the tryit more than I should stop doing so
You are probably running into the same origin policy here.
Try saving the XML-file locally and load it from there instead of the remote server of w3schools.