I have an XML file:
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product>
<id>246</id>
<code>Ash07-001</code>
<image>C:\BowlPhotos\Thumbs\Ash07-001tmb.jpg</image>
</product>
<product>
<id>247</id>
<code>Ash07-004</code>
<image>C:\BowlPhotos\Thumbs\NoBowltmb.jpg</image>
</product>
<product>
<id>248</id>
<code>Ash07-005</code>
<image>C:\BowlPhotos\Thumbs\Ash07-005tmb.jpg</image>
</product>
</products>
And read it with this code:
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("product");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("code")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("image")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
And that works to get all of the file.
What if I only want the product with the id of 247? How do I pull that entire product out and print just that one?
You can write code like this . It will not execute code for displaying the content if the id is not 247