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 />

elementCd.appendChild(elementLabel);<br />

var elementDate = obj<strong>XML</strong>.createElement("date");<br />

var textDate = obj<strong>XML</strong>.createTextNode(date);<br />

elementDate.appendChild(textDate);<br />

elementCd.appendChild(elementDate);<br />

var root = obj<strong>XML</strong>.documentElement;<br />

root.appendChild(elementCd);<br />

document.all("xmlresult").value = obj<strong>XML</strong>.xml;<br />

}<br />

The first six lines gather values from the HTML table and assign them to<br />

variables.<br />

Line seven calls the createElement() method to create a new element. The<br />

createElement() method requires one argument, which is the name of the element<br />

that you want to create. In this example, you’re creating a cd element. The<br />

createElement() method returns a reference to the new element.<br />

Line eight calls the setAttribute() method to assign a value to the attribute of the<br />

new element. The setAttribute() method requires two arguments. The first argument<br />

is the name of the attribute that’s being set and the second argument is the value<br />

assigned to the new attribute.<br />

Lines 9 through 30 create child elements for the element. Notice that each<br />

child element is actually two nodes—one for the element and the other for the text.<br />

Line 31 displays the <strong>XML</strong> document, as we show here:<br />

<br />

<br />

<br />

<br />

U2<br />

How to Dismantle an Atomic Bomb<br />

13.98<br />

Interscope Records<br />

2004-11-23<br />

<br />

<br />

Led Zeppelin<br />

Physical Graffiti<br />

22.99<br />

Atlantic<br />

1994-08-16<br />

<br />

175

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

Saved successfully!

Ooh no, something went wrong!