02.06.2013 Views

XML Demystified

XML Demystified

XML Demystified

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 10 MS<strong>XML</strong><br />

So far in this chapter, you’ve learned how to insert one <strong>XML</strong> document into another.<br />

In addition to this, you’ll need to select, extract, delete, and validate information<br />

contained in an <strong>XML</strong> document.<br />

We’ll explore how to perform these common tasks in this section. First we’ll<br />

show you how to create an HTML page that enables you to execute each of these<br />

tasks. In a real-world application, of course, these tasks would be built into your<br />

application.<br />

Here’s the HTML page we’ll use for these examples:<br />

<br />

<br />

Select Artist:<br />

<br />

Display Titles<br />

Delete Nodes w/UPC:<br />

<br />

Validate Document<br />

<br />

<br />

The SelectArtist() Function—<br />

Filtering an <strong>XML</strong> Document<br />

The SelectArtist() function is used to display information about an artist’s CDs by<br />

entering the name of the artist and then having the SelectArtist() search and display<br />

related information about the artist’s CDs. Here’s the SelectArtist() function:<br />

function SelectArtist(artist)<br />

{<br />

var objNodes = obj<strong>XML</strong>.selectNodes(<br />

"/catalog/cd[artist='" + artist + "']")<br />

if(objNodes.length == 0)<br />

{<br />

alert("Could not find artist with name " + artist);<br />

177<br />

Select, Extract, Delete, and Validate

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!