i got a problem with ajax and xml. i have a xml file, which covers the status of several buttons. so now in my webpage i wand to check the actual status of each button. here is the xml file:
<?xml version="1.0" encoding="utf-8"?>
<btn_status>
<btn1>
<titel>Button 1</titel>
<status>inactive</status>
</btn1>
<btn2>
<titel>Button 2</titel>
<status>active</status>
</btn2>
</btn_status>
my ajax script looks like this.
document.write("<p>Status der Buttons</p>");
document.write("<table border='1'>");
var xmlContent=xmlDoc.getElementsByTagName("btn1");
for (i=0;i<xmlContent.length;i++)
{
document.write("<tr><td>");
document.write(xmlContent[i].getElementsByTagName("titel")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(xmlContent[i].getElementsByTagName("status")[0].childNodes[0].nodeValue );
if(btnStatus1=xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue == 'active'){
document.write("<img src='Normal.png' />");
}
else // ie5/6
{
document.write("<img src='error.png' />");
}
document.write("</td></tr>");
}
the problem is now, that the if/else only covers the status of btn1 not the others and now i dont know how to questioned the status of btn2 and the following ones. something like
btnStatus2=btn2.status...
anyone got an idea :/
sry solved it myself, just had to cound torwards the child elements...
if(btnStatus2=xmlDoc.getElementsByTagName("status")[1].childNodes[0].nodeValue == 'active'){
document.write("<img src='Normal.png' />");
}
else // ie5/6
{
document.write("<img src='error.png' />");
}
document.write("</td></tr>");
}
and for the third entry:
var xmlContent=xmlDoc.getElementsByTagName("btn3");
for (i=0;i<xmlContent.length;i++)
{
document.write("<tr><td>");
document.write(xmlContent[i].getElementsByTagName("titel")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(xmlContent[i].getElementsByTagName("status")[0].childNodes[0].nodeValue );
if(btnStatus3=xmlDoc.getElementsByTagName("status")[2].childNodes[0].nodeValue == 'active'){
document.write("<img src='Normal.png' />");
}
else // ie5/6
{
document.write("<img src='error.png' />");
}
document.write("</td></tr>");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.