Introduction to Ajax
11. Parsing XML
Join the Discussion
Once you have got your response back from the server you need to break it up into its component parts (assuming that there is more than one pices to the information) and then use the DOM to update the web page with the information. Where we get the respose from the responseText field (which is always available) we then have to parse the content ourselves in order to determine what parts of the content are what.
When we retrieve XML from the server we have both the responseText and the responseXML fields being populated and the advantage to using responseXML is that the work of parsing the XML is done for us.
var xmlDoc = request.responseXML;
var priceArray = xmlDoc.getElementsByTagName('price');