Parsing an XML File in 7.0 Browsers and Safari

C

CES

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
 
M

Martin Honnen

CES wrote:

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);
}
 
M

Martin Honnen

Martin Honnen wrote:

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

Should have been

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top