Why is setAttribute not changing my xml?



I have the following xml (it's a snippet of larger xml):



<fillet index="3">
<imgsrc>somesource</imgsrc>
<width>0.31</width>
<cid>9351</cid>
<sku>somesku</sku>
</fillet>


I want to change the index="3", to index="2"


This is my javascript code:



var parser = new DOMParser(); //create a new DOMParser
var doc = parser.parseFromString(mattes_get_mattes_xml(), "application/xml"); //convert the string to xml
if ("undefined" != typeof(doc.getElementsByTagName('fillet')[index]))
{
if (mattes_remove_layer_call === false)
{
doc.getElementsByTagName('fillet')[index].innerHTML = "";
}
else
{
console.log(doc.getElementsByTagName('fillet')[index].getAttribute("index"));
doc.getElementsByTagName('fillet')[index].setAttribute("index", (index - 1)); //switch the index number for the top layer
console.log(doc.getElementsByTagName('fillet')[index].getAttribute("index"));
}
}
var serializer = new XMLSerializer(); //create a new XMLSerializer
mattes_mattes_xml = serializer.serializeToString(doc); //convert the xml back to a string


However, the setAttribute is not changing the value. I know this because the console.log statements are both outputting 3.


No comments:

Post a Comment