Monday, February 12, 2007

Chap 6

This chapter focuses on XML for requests and responses. XML is about to help web servers say more in their responses.

Next the book revists the Boards 'R' Us website. It's been working well, but now the business has expanded to 3 products and is in need of a way of updating totals from the server for all 3 lines at once.

Page 345 shows the lines of XML that can be returned by the server to the webpage.

The DOM is so versatile that not only does it work with HTML, but it also works with XML.

FYI: As your browser sees your HTML as a DOM tree, web browsers automatically convert XML into DOM trees. You can work with more than one DOM tree in the same JavaScript function. HTML and XML elements are both just element nodes in the DOM. The responseXML property always returns a DOM document object, even if the XML in the DOM tree is only a single element, or just a single text node.

For the Boards 'R' Us page, we can just take the values from the XML DOM and place them in the HTML DOM.

Instead of using getElementByID() for HTML DOM, we can use getElementsByTagName() . This will return an array of all the elements named "boards-sold" in the xmlDoc DOM tree.

The code is: var firstBoardsSoldElement = xmlDoc.getElementsByTagName("boards-sold")[0];

0 Comments:

Post a Comment

<< Home