Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / November 2004



Tip: Looking for answers? Try searching our database.

Parsing an XML File in 7.0 Browsers and Safari

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CES - 30 Nov 2004 18:30 GMT
I'm sorry for the 101 question but I'm having problems loading/parsing a
simple XML file into to above browsers. I was wondering if anyone has seen
and can point me to a SIMPLE example that a beginner could follow.

The examples I've found work with the all the 7.x browsers but don't seem to
work with Safari 1.2+ and I don't know enough to figure out why.

Any Help would be greatly appreciated...
CES
Martin Honnen - 30 Nov 2004 18:39 GMT
> The examples I've found work with the all the 7.x browsers but don't seem to
> work with Safari 1.2+ and I don't know enough to figure out why.

As far as I remember Safari 1.2 implements XMLHttpRequest so you can do
  var httpRequest;
  if (typeof XMLHttpRequest != 'undefined') {
    httpRequest = new XMLHttpRequest();
    httpRequest.open('GET', 'file.xml', true);
    httpRequest.onreadystatechange = function () {
      if (httpRequest.readyState == 4 && httpRequest.status == 200) {
        var xmlDocument = httpRequest.responseXML;
        // now process xmlDocument here e.g.
        alert('XML document has ' +
xmlDocument.getElementsByTagName('*') + ' elements.');
      }
    }
    httpRequest.send(null);
  }

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/

Martin Honnen - 30 Nov 2004 18:42 GMT
>         alert('XML document has ' +
> xmlDocument.getElementsByTagName('*') + ' elements.');

Should have been

        alert('XML document has ' +
xmlDocument.getElementsByTagName('*').length + ' elements.');

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.