By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,480 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,480 IT Pros & Developers. It's quick & easy.

Basic Ajax question

P: n/a
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
Jul 20 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Jul 20, 11:35 am, ChrisW <c.c.w...@gmail.comwrote:
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
Jul 21 '08 #2

P: n/a
On 21 Jul, 03:12, Peter Michaux <petermich...@gmail.comwrote:
On Jul 20, 11:35 am, ChrisW <c.c.w...@gmail.comwrote:
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
Jul 21 '08 #3

P: n/a
On Jul 21, 6:03 am, ChrisW <c.c.w...@gmail.comwrote:

[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/20...03/16/XML-Prog
http://www.tbray.org/ongoing/When/20.../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
Jul 21 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.