I've checked out this page (and it works fine) in FF, IE, Opera, Chrome and Safari:
http://www.w3schools.com/dom/tryit.asp?filename=try_dom_list_loop
But when I try and tweak it for a site I'm working on, it doesn't work in Chrome and Safari.
I used their exact external javascript to load the xml file:
Expand|Select|Wrap|Line Numbers
- function loadXMLDoc(dname)
- {
- var xmlDoc;
- if (window.XMLHttpRequest)
- {
- xmlDoc=new window.XMLHttpRequest();
- xmlDoc.open("GET",dname,false);
- xmlDoc.send("");
- return xmlDoc.responseXML;
- }
- // IE 5 and IE 6
- else if (ActiveXObject("Microsoft.XMLDOM"))
- {
- xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async=false;
- xmlDoc.load(dname);
- return xmlDoc;
- }
- alert("Error loading document");
- return null;
- }
Expand|Select|Wrap|Line Numbers
- <script type="text/javascript">
- xmlDoc=loadXMLDoc("xml/stations.xml");
- x=xmlDoc.getElementsByTagName('city');
- for (i=0;i<x.length;i++)
- {
- document.write(x[i].childNodes[0].nodeValue);
- document.write("<br />");
- }
- </script>
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="utf-8"?>
- <stations>
- <station>
- <city>City 1</city>
- <freq>105.7 FM</freq>
- </station>
- <station>
- <city>City 2</city>
- <freq>90.3 FM</freq>
- </station>
- </stations>
I don't understand, any help would great. Thanks in advance!