Closed Thread
Results 1 to 8 of 8

Thread: Reading XML Data

  1. #1
    so1i's Avatar
    so1i is offline Programming Professional
    Join Date
    Sep 2009
    Location
    Aberystwyth, United Kingdom
    Posts
    309
    Rep Power
    0

    Reading XML Data

    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:
    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>
    Thanks in advance guys!

    -Chris
    Last edited by so1i; 09-19-2009 at 07:26 PM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Reading XML Data

    You are missing a ) on line 175):

    Code:
    else if (ActiveXObject("Microsoft.XMLDOM");
    You have a ; instead of the needed ).

  4. #3
    so1i's Avatar
    so1i is offline Programming Professional
    Join Date
    Sep 2009
    Location
    Aberystwyth, United Kingdom
    Posts
    309
    Rep Power
    0

    Re: Reading XML Data

    Quote Originally Posted by Jordan View Post
    You are missing a ) on line 175):

    Code:
    else if (ActiveXObject("Microsoft.XMLDOM");
    You have a ; instead of the needed ).
    Ah! Knew it would be something ridiculous! Thanks man.

    EDIT: Just actually tried that, and it still isn't displaying any of the data, even with the change. Notice any other errors? :S

  5. #4
    so1i's Avatar
    so1i is offline Programming Professional
    Join Date
    Sep 2009
    Location
    Aberystwyth, United Kingdom
    Posts
    309
    Rep Power
    0

    Re: Reading XML Data

    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.

  6. #5
    Jordan Guest

    Re: Reading XML Data

    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.

  7. #6
    so1i's Avatar
    so1i is offline Programming Professional
    Join Date
    Sep 2009
    Location
    Aberystwyth, United Kingdom
    Posts
    309
    Rep Power
    0

    Re: Reading XML Data

    Quote Originally Posted by Jordan View Post
    What was the last error?
    Bit of an embarrassing error. I had "windows.XMLHttpRequest", rather than "window.XMLHttpRequest"

    Quote Originally Posted by Jordan View Post
    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.
    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!

  8. #7
    Jordan Guest

    Re: Reading XML Data

    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.

  9. #8
    so1i's Avatar
    so1i is offline Programming Professional
    Join Date
    Sep 2009
    Location
    Aberystwyth, United Kingdom
    Posts
    309
    Rep Power
    0

    Re: Reading XML Data

    Quote Originally Posted by Jordan View Post
    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.
    Cheers.

    I have actually been using chrome for a while now, I really like the browser tbh, and I think the inspector is a really good feature. Will definitely try it out for debugging this kind of thing in the future, thanks.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Reading data from machine with RS232
    By egetunks in forum Visual Basic Programming
    Replies: 2
    Last Post: 05-29-2011, 08:24 AM
  2. reading EXIF data
    By Root23 in forum C# Programming
    Replies: 4
    Last Post: 10-13-2010, 09:48 AM
  3. C++ Reading Data file into Struct Array HELP!!!
    By kevinsabres in forum C and C++
    Replies: 6
    Last Post: 04-21-2010, 11:48 AM
  4. Replies: 5
    Last Post: 02-28-2009, 12:21 AM
  5. reading data from a website?
    By ClemsonCS in forum C and C++
    Replies: 8
    Last Post: 02-24-2008, 09:26 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts