I have this code for removing unwanted items from xml list, based on their child's attributes.
var xmlDoc=loadXMLDoc(filePath);
var unwanted = xmlDoc.querySelectorAll("item > KlasId[id='1']");
Array.prototype.map.call(unwanted, function(element){
element.parentNode.parentNode.removeChild(element.parentNode);
});
This works just fine and removes all the item
nodes with KlasId
children of id=1
.
What i want now is to remove item
s based on KlasId
value instead of attribute (for example value 101010), but it somehow doesnt work:
var unwanted = xmlDoc.querySelectorAll("item > KlasId[value='101010']");
etc...
My XML:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<dataroot>
<item>
<KlasId id='1'>101010</KlasId>
</item>
<item>
<KlasId id='2'>101010</KlasId>
</item>
<item>
<KlasId id='3'>202020</KlasId>
</item>
</dataroot>
EDIT:
function loadXMLDoc(filename)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else // code for IE5 and IE6
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",filename,false);
xhttp.send();
return xhttp.responseXML;
}