« Response to Mike's blog: In need of Javascript assistance | Main

Response to Mike's blog: In need of Javascript assistance

Mike,
Reading your blog post, I did not quite understand what your problems were in parsing the xml. But, I am posting a small chunk of code that I used to parse my xml file. May be you can make use of this.

Basically, it strips off the Title elements from the xml (rerturned by your ISBN call) and creates an element node to display it in the HTML page. You can repeat this process for other elements that you have. Note that the DOM methods are case sensitive. So, double check the tag names you pass to these methods. Hope this helps.

// NOTE : you should have a div with an id resultArea in your html file
var resultTree = document.getElementById('resultArea');

// retrieve the title element
var titles=xmlDoc.getElementsByTagName('Title');
var title = titles[o].childNodes[0].nodeValue;

// create an element node
tempElementNode = document.createElement("h4");

// createa text node with the value extracted from title element
tempTextNode = document.createTextNode("Title : " + title);

// add the text node to the element node previously created
tempElementNode.appendChild(tempTextNode);

// add the resulting element to the result area ..so that
// the title is displayed in the screen
// NOTE : you should have a div with an id resultArea in your html file
resultTree.appendChild(tempElementNode);

Archives

Recent Comments