The index() Method

As you've seen many times s in your study of XML, the child nodes of XML are automatically numbered or indexed starting at 0. The index() method allows for the selection of a single node by extracting the node with a specific index.

Go back to the HTML file and modify the GrabNodes() function to match Listing 17.2.

Listing 17.2 Selecting Nodes Based on Their Index Values
 1: function GrabNodes()
 2: {
 3:  var NodeData=DataSource1.selectNodes("//Book/*[index()=2]");
 4:  moveNode=NodeData.nextNode();
 5:  while(moveNode!=null)
 6:  {
 7:   document.write(moveNode.text+"<BR>");
 8:   moveNode=NodeData.nextNode ();
 9:  }
10: }

When you view the file in IE, the output is the contents of the <Publisher> nodes. Since you're using the selectNodes() ...

Get Sams Teach Yourself XML in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.