Hi there,
This is probably going to turn out to be a very newbie question, however over the last couple of days I have decided to begin to learn how to read and manipulate XML data, for web development.
I was trying a couple of the tutorials over at w3schools.com, and I believe I have understood it and know what's going on, but.. I just can't get this simple tester I have set up to work... so if someone could spot the reason and let me know I'd be most grateful (it's bound to be something really stupid that I've missed, but do bare with me!).
Basically I set up an XML file (found here), and then have tried to just show the data in a <div> on an html page (found here).
JScript embedded in my HTML:
Thanks in advance guys!Code:<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>XML Test</title> <script type="text/javascript"> var xmlDoc; if (windows.XMLHttpRequest) { xmlDoc=new window.XMLHttpRequest(); xmlDoc.open("GET","details.xml",false); xmlDoc.send(""); xmlDoc=xmlDoc.responseXML; } // IE 5 and 6 else if (ActiveXObject("Microsoft.XMLDOM"); { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("details.xml"); } var x=xmlDoc.getElementsByTagName("person"); i=0; function display() { firstname=x[i].getElementsByTagName("first_name")[0].childNodes[0].nodeValue); lastname=x[i].getElementsByTagName("last_name")[0].childNodes[0].nodeValue); txt="First Name: " + firstname +"<br/><br/>Last Name: " + lastname; document.getElementById("show").innerHTML=txt; } </script> </head> <body onLoad="display()"> <div id='show'></div> </body> </html>
-Chris
Last edited by so1i; 09-19-2009 at 07:26 PM.
You are missing a ) on line 175):
You have a ; instead of the needed ).Code:else if (ActiveXObject("Microsoft.XMLDOM");
Fixed! Just were some more silly typos which I eventually found! ....I apparently shouldn't try to learn new things when tired!
Thanks for the help.
What was the last error?
Also, how are you debugging it? There are some tools you can use which will help you find errors. I find that IE is decent at reporting JavaScript errors when double-clicking the error icon in the bottom left.
Bit of an embarrassing error. I had "windows.XMLHttpRequest", rather than "window.XMLHttpRequest"
To be honest I was just debugging it manually, trying to compare it to others to find discrepencies. However I just tried the IE method, and that works great! Thanks!
No problem. There is also FireBug for FireFox which works well: https://addons.mozilla.org/en-US/firefox/addon/1843
Chrome/Safari/Webkit browsers have the inspector which is awesome as well.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks