you’re on your way �
375
xml versus json
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
// Get the updated totals from the XML response
var xmlDoc = request.responseXML;
var xmlBoards =
xmlDoc.getElementsByTagName(“boards-sold”)[0];
var totalBoards = xmlBoards.rstChild.nodeValue;
var xmlBoots =
xmlDoc.getElementsByTagName(“boots-sold”)[0];
var totalBoots = xmlBoots.rstChild.nodeValue;
var xmlBindings =
xmlDoc.getElementsByTagName(“bindings-sold”)[0];
var totalBindings = xmlBindings.rstChild.nodeValue;
totals
boards-sold
boots-sold
bindings-sold
“1710“
“315“
“85“
Here’s the DOM tree for
that XML document...
You use the DOM to work with XML
...and here’s a little bit of DOM
code from Chapter 6.
Web Browser
getNew Totals()
<script>
var request...
function foo()
{
...
}
</script>
Internet Explorer
Firefox
Opera
Safari
Mozilla
JavaScript
In your JavaScript, you use
the DOM to work with a
server’s XML response.