OK so I wrote a script that traverses an xml document. Click here to download the script. This script works fine when a <URL> element is in the <STORY> element, but when a <URL> does not exist the script stops writing everything after that point in the XML. What I was trying to do was add a simple if routine to the script to check for a <URL> and if not present skip it and go on. Unfortunelty I dont know very much javascript (which is evident by my use of var b = tree.childNodes[i].childNodes[2]) so I failed. Can anyone help me write the routine to check for the <URL>.

the if statement is highlighted in red here.

function traverse(tree) {
for(var i=0; i<tree.childNodes.length;i++){
document.write('<TR><TD>')
document.write('<DIV CLASS = "header">')
document.write(tree.childNodes[i].childNodes[0].text)
document.write('</DIV>')
document.write('<DIV CLASS = "general">')
document.write(tree.childNodes[i].childNodes[1].text)
document.write('</DIV>')
var b = tree.childNodes[i].childNodes[2]
if(b > 1){
document.write('<DIV>')
document.write('<A HREF = "'+tree.childNodes[i].childNodes[2].text+'" TARGET = "_blank" CLASS = "url">'+tree.childNodes[i].childNodes[2].text+ '</A>')
document.write('</DIV>')}
document.write('</TR></TD>')

}

}


Thank you in advance.