The question is : How can I do this table call using ajax. Only display the values when a tag "code" is with a value "10 222" the xml is
<?xml version='1.0' encoding='utf-8' ?>
<?xml-stylesheet type='text/xsl' href='thefile.xsl' ?>
<inv100 xmlns:xsi='http://ift.tt/1pu4Cto'
xsi:noNamespaceSchemaLocation='archivo.xsd'>
<tab_inv>
<Descripcion> Food for dog </Descripcion>
<precio> 6.55 </precio>
<code> 01 22 </code>
</tab_inv>
<tab_inv>
<Descripcion> Food for cat </Descripcion>
<precio> 8.55 </precio>
<code> 10 222 </code>
</tab_inv>
<tab_inv>
<Descripcion> Food for dragons </Descripcion>
<precio> 122.55 </precio>
<code> 14 2212 </code>
</tab_inv>
</inv100>
And this is the script
<script>
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xmlhttp.open("GET", "thefile.xml", true);
xmlhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th>Descripcion</th><th>Precio</th></tr>";
var x = xmlDoc.getElementsByTagName("tab_inv");
for (i = 0; i <x.length; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("Descripcion")[0].childNodes[0].nodeValue
+
"</td><td>" +
x[i].getElementsByTagName("precio")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("demo").innerHTML = table;
}
</script>
The actual script only display all the information, but I want to display only the tags contained on "tab_inv" with the tag "code" on value 10 222.
thanks !
Aucun commentaire:
Enregistrer un commentaire