Problem with XML format after insert a new XMLNode
In my node app I have to insert a new XMLnode for identify it later. I developed some code where I expected the right result.
It is really simple:
var xmlDoc = new DOMParser().parseFromString(dataRegelWerk); //Incomming dataif(allok == false){ var root = xmlDoc.documentElement; var varselem = xmlDoc.getElementsByTagName('vars')[0]; var newEle = xmlDoc.createElement('TCafe'); var att1 = xmlDoc.createAttribute("initvalue"); att1.value = "1"; var att2 = xmlDoc.createAttribute("type"); att2.value = "int"; newEle.setAttributeNode(att1); newEle.setAttributeNode(att2); root.insertBefore(newEle, varselem); }var myFile = serializer.serializeToString(xmlDoc); //Put back to string to store in db
Is there anything wrong with my code or do I expect a wrong thing? Maybe I have to close the new XMLNode? (I expected the last / will do it.
Any help will be great.
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.