Hello friends, I have a problem to make the code that gives me the correct information that I look for my WEB. But I told them: I have an xml file that goes something like this:
<?xml version='1.0' encoding='utf-8' ?>
<?xml-stylesheet type='text/xsl' href='archivo.xsl' ?>
<bodega>
<inventario>
<Descripcion>Comida de tortuga</Descripcion>
<Codigo>0010</Codigo>
<Clasif>11 200</Clasif>
<precio>1200</precio>
</inventario>
<inventario>
<Descripcion>Comida de gato</Descripcion>
<Codigo>0080</Codigo>
<Clasif>12 700</Clasif>
<precio>1200</precio>
</inventario>
<inventario>
<Descripcion>Collar de perro</Descripcion>
<Codigo>0120</Codigo>
<Clasif>14 111</Clasif>
<precio>1200</precio>
</inventario>
</bodega>
Which I call from a predefined button with the following script:
<script>
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xmlhttp.open("GET", "archivo.xml", true);
xmlhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th>Descripcion</th><th>Codigo</th>
<th>Precio</th></tr>";
var x = xmlDoc.getElementsByTagName("inventario");
for (i = 0; i <x.length; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("Descripcion")
[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("Codigo")[0].childNodes[0].nodeValue
+
"</td><td>"+
x[i].getElementsByTagName("precio")[0].childNodes[0].nodeValue
+
"</td></tr>";
}
document.getElementById("tabla1").innerHTML = table;
}
</script>
This gives me inside a table with id "tabla1" all the data of my xml, but since they will realize this file is just an example, in the real one I have hundreds of articles that I am looking for to link with a condition that shows only the articles with certain classification. To create a button with function call for each of the classifications and thus call only certain items and not the entire file.
Try with a while (), in several ways but without success, I look for the "inventory" tags that contain the "Clasif" with the numerical value 14 111 to be shown only ignoring the rest to display. XP
Any ideas? Greetings and a thousand thanks Hold Latinos!