i'm trying to display een xml file in een html page but when a tagname has an empy null value it stops at that point and wont display the rest of the file
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","./test.XML",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='0'>");
var x=xmlDoc.getElementsByTagName("file");
for (i=0;i<x.length;i++)
{
document.write("<table width=100% border=0 cellpadding=0 cellspacing=0 class=table><tr><td>"+
"<table width=100% border=0 cellpadding=0 cellspacing=0 class=table>"+
"<tr><td width=6%></td><td align=left>"+x[i].getElementsByTagName("nr")[0].childNodes[0].nodeValue+"<br><br></td><td></td><td align=left>text<br><br></td></tr>"+
"<tr><td align=left>"+x[i].getElementsByTagName("nrorder")[0].childNodes[0].nodeValue+"</td>");
if(x[i].getElementsByTagName("text")[0].childNodes[0].length = 0)
{
document.write("<td></td>");
}
else
{
document.write("<td align=left><b>"+x[i].getElementsByTagName("text")[0].childNodes[0].nodeValue+"</b></td>");
}
}
</script>
</center>
</div>
</body>
</html>
here the test xml file
<file>
<nr>1</nr>
<nrorder>101</nrorder>
<text>1</text>
</file>
<file>
<nr>2</nr>
<nrorder>102</nrorder>
<text></text>
</file>
<file>
<nr>33333333333</nr>
<nrorder>103</nrorder>
<text>33333333</text>
</file>
So when i get to of 2 it does not go on to 3. How can i or move on to the next one? without stopping at the second
if i remove the if statment i can display everything but need this element
the fix is:
if (x[i].getElementsByTagName("text")[0].childNodes.length == 0) {
document.write("<td align=left><b></b></td>")
}
else {
document.write("<td align=left><b>"+x[i].getElementsByTagName("text")[0].childNodes[0].nodeValue+"</b></td>");
}
if (x[i].getElementsByTagName("text")[0].childNodes.length == 0) {
document.write("<td align=left><b></b></td>")
}
else {
document.write("<td align=left><b>"+x[i].getElementsByTagName("text")[0].childNodes[0].nodeValue+"</b></td>");
}