Basic Ajax question

C

ChrisW

I'm fairly new to Ajax - I understand the principles of XML, can do
the PHP side, but am getting a bit lost with the JavaScript.

I've seen a couple of different ways of using JS to manipulate the
XML: 1 way using the getElementsByTagName method (as advocated by
W3Schools - http://www.w3schools.com/Dom/dom_nodes_get.asp) and a
seemingly different method (http://scriptasylum.com/tutorials/
xml_javascript/xml_javascript.html) - is either way recommended more
or less (or any other way I haven't found yet)?

I also haven't found any kind of decent API - is there one about? For
example, I want to be able to get the value of an attribute from one
of my nodes - I tried

xmlDoc.getElementsByTagName("info")
[0].childNodes[0].getAttribute("type");

but it doesn't work (in either IE or Firefox), but I can't find any
other way to do it. Cross-browser compatibility is also a big concern
for me, so if anyone can point me in the direction of a decent
tutorial, I'd be most grateful!

Thanks,
Chris
 
P

Peter Michaux

I'm fairly new to Ajax - I understand the principles of XML, can do
the PHP side, but am getting a bit lost with the JavaScript.

I've seen a couple of different ways of using JS to manipulate the
XML: 1 way using the getElementsByTagName method (as advocated by
W3Schools -http://www.w3schools.com/Dom/dom_nodes_get.asp) and a
seemingly different method (http://scriptasylum.com/tutorials/
xml_javascript/xml_javascript.html) - is either way recommended more
or less (or any other way I haven't found yet)?

I also haven't found any kind of decent API - is there one about? For
example, I want to be able to get the value of an attribute from one
of my nodes - I tried

xmlDoc.getElementsByTagName("info")
[0].childNodes[0].getAttribute("type");

but it doesn't work (in either IE or Firefox), but I can't find any
other way to do it. Cross-browser compatibility is also a big concern
for me, so if anyone can point me in the direction of a decent
tutorial, I'd be most grateful!

Do you know about JSON? It is generally preferred over XML these days.
It is easier to extract data from the JSON when it has been converted
to a JavaScript object than it is to extract data out of an XML
document.

http://json.org/

Peter
 
C

ChrisW

I'm fairly new to Ajax - I understand the principles of XML, can do
the PHP side, but am getting a bit lost with the JavaScript.
I've seen a couple of different ways of using JS to manipulate the
XML: 1 way using the getElementsByTagName method (as advocated by
W3Schools -http://www.w3schools.com/Dom/dom_nodes_get.asp) and a
seemingly different method (http://scriptasylum.com/tutorials/
xml_javascript/xml_javascript.html) - is either way recommended more
or less (or any other way I haven't found yet)?
I also haven't found any kind of decent API - is there one about? For
example, I want to be able to get the value of an attribute from one
of my nodes - I tried
xmlDoc.getElementsByTagName("info")
[0].childNodes[0].getAttribute("type");

but it doesn't work (in either IE or Firefox), but I can't find any
other way to do it.  Cross-browser compatibility is also a big concern
for me, so if anyone can point me in the direction of a decent
tutorial, I'd be most grateful!

Do you know about JSON? It is generally preferred over XML these days.
It is easier to extract data from the JSON when it has been converted
to a JavaScript object than it is to extract data out of an XML
document.

http://json.org/

Peter

Thanks for the link, though I still have a few questions.

Is XML becoming obsolete? A couple of modules I did at a large UK
university a couple of years ago seemed to promote XML as the ultimate
data-handling tool, and that the XML-based databases etc were the best
thing ever to have been invented.

There are still reasons why I'd like to understand the XML-based
methods - a lot of the ways of storing data in the scientific field I
work in uses XML (e.g. STMML, MathML, and also RSS)

I'm still worried about the issue of cross-browser compatibility - are
the JS methods for manipulating JSON data better suited for this than
the methods I found for XML, which only work in IE?

Thanks,
Chris
 
P

Peter Michaux

[snip]
Is XML becoming obsolete?

No. Not at all.

Many folks are choosing to use JSON as their data transport format
rather than choosing XML.

A couple of modules I did at a large UK
university a couple of years ago seemed to promote XML as the ultimate
data-handling tool, and that the XML-based databases etc were the best
thing ever to have been invented.

Some interesting perspectives:

http://www.tbray.org/ongoing/When/200x/2003/03/16/XML-Prog
http://www.tbray.org/ongoing/When/200x/2003/03/24/XMLisOK

There are still reasons why I'd like to understand the XML-based
methods - a lot of the ways of storing data in the scientific field I
work in uses XML (e.g. STMML, MathML, and also RSS)

If the systems already use XML then it is probably best to go with the
flow and use XML.

I'm still worried about the issue of cross-browser compatibility - are
the JS methods for manipulating JSON data better suited for this than
the methods I found for XML, which only work in IE?

Extracting data from a JSON text that has been converted to a
JavaScript object is much easier than extracting data from an XML
document.

Peter
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top