Apr 14, 2010

DOM Is Not So Bad


After studying the DOM (document object model) for a couple of weeks it is not so difficult after all. In fact, the DOM makes things very easy by breaking down the XML into sections (trees) by their order in the document. Once you get the server to pull the XML from the API's server the rest is surprisingly easy.


Once the code is pulled up from the server onto your server you just use Javascript to parse the XML. For instance, lets say you have a tag that contains the price data. You would get the price tag data by assigning a variable to it. For example, var price = requestDocEbay.getElementsByTagName("price")[0];. The code is looking for the "price" tag then going no further. Next you have to assign a variable to get the data from the first tag node. You do this with the following code. var priceText = price.firstChild.nodeValue. What this code does is get the data from inside the tag. You can find a great example on page 361 from our textbook. This is the example I used for the group project and it works out great.


For further insight please check out the following links.




IBM Article




Cover Pages


The DOM may seem intimidating at first but don't let it scare you. It really helps to break down the DOM into little pieces. Do each section of your code, that way the code is not huge and does not scare you away with pages of code. Finally I can say this has been a good week of programming!!

1 comment:

  1. There you go Jeremy you finally understood what it really does and how one has to use it. I liked DOM so much that I used it in my Individual Iteration 2. Way to Go Jeremy!

    ReplyDelete