javascript - Reading a specific product from an xml file of products -


i have 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 code:

document.write("<table border='1'>"); var x=xmldoc.getelementsbytagname("product"); (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 works of file.

what if want product id of 247? how pull entire product out , print one?

document.write("<table border='1'>"); var x=xmldoc.getelementsbytagname("product"); (i=0;i<x.length;i++)   {            if(x[i].getelementsbytagname("id")[0].childnodes[0].nodevalue != 247) continue;           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>"); 

you can write code . not execute code displaying content if id not 247


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -