Mar25
Crossword Web App, Part 6 0 Comments
Although it’s easy to get Javascript to read from an XML file, pulling out the appropriate data can sometimes be tricky. Here are some tips to help you tame the XML beast.
Part 6: Taming XML
Let’s look at a typical XMLHttpRequest again.
var url = 'xml/070814.xml';var xmlhttp = new XMLHttpRequest(); if (xmlhttp != null) {xmlhttp.onreadystatechange = stateChange;xmlhttp.open('GET', url, true);xmlhttp.send(null);} else {alert('Your browser does not support XMLHTTP.'); }} function stateChange() {if (xmlhttp.readyState == 4) {if (xmlhttp.status == 200) {/*A status of 200 means that the XML file wasloaded and parsed without error. At this pointyou'll want to sort through all of the data sothat it can be used by your program. I'll giveyou some tips on how to do this in the nextupdate.*/} else {alert('Problem retrieving XML data.');}}}Figure 1. The basic structure of an XMLHttpRequest