You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
CHAPTER 10 MS<strong>XML</strong><br />
details of any errors that might have occurred. This is an instance of the<br />
I<strong>XML</strong>DOMParseError object. It checks if the errorCode is not zero, which means<br />
an error occurred. If so, then the error message is displayed on the screen.<br />
The sixth line displays the <strong>XML</strong> document in the text area of the HTML page.<br />
Look carefully and you’ll notice that the line references the <strong>XML</strong> property of the<br />
obj<strong>XML</strong> variable. Remember that the obj<strong>XML</strong> variable references the DOMDocument.<br />
The <strong>XML</strong> property of the DOMDocument contains the <strong>XML</strong> representation of the<br />
DOMDocument. Remember, the DOM is a tree type structure. The <strong>XML</strong> property<br />
essentially serializes the DOM back to its familiar markup form.<br />
Adding a New Element<br />
The <strong>XML</strong> document contains information about CDs. Each CD has a upc attribute<br />
and five child elements. Add the following CD to the catalog:<br />
<br />
Phish<br />
Live Phish, Vol. 15<br />
26.99<br />
ELEKTRA/WEA<br />
2002-10-29<br />
<br />
You’ll need to use four different functions to determine where to place the new<br />
CD within the <strong>XML</strong> document. These functions are<br />
• InsertFirst() Put the new entry at the beginning of the list<br />
• InsertLast() Put the new entry at the end of the list<br />
• InsertBefore() Put the new entry before the CD with the given upc<br />
attribute<br />
• InsertAfter() Put the new entry after the CD with the given upc attribute<br />
Each function is called by an option on the HTML form. Options appear in the<br />
first column of the table. The user of the application decides the position of the new<br />
CD within the <strong>XML</strong> document by selecting the appropriate option.<br />
The first two options place the new CD at the beginning or at the end of the <strong>XML</strong><br />
document, respectively. The last two options require the user to specify a UPC. The<br />
UPC is the identifier for a CD that’s already in the <strong>XML</strong> document. The function<br />
then places the new CD either before or after the CD that the user specifies.<br />
The second column contains a text area containing information about the new<br />
CD. We’ve provided a default value when the page loads, but you can change this<br />
161