I would like to modify an element of my xml. I have to query it to find it, and then I only seem to be able to modify a copy of it. I use: clientXML.querySelector("[id=XMLIssue-9]").childNodes[2].textContent;
to isolate the element in question. I would like to just replace the element with this one newXMLIssue.childNodes[0]
. They both have the exact same structure. I cant do:
clientXML.querySelector("[id=XMLIssue-9]") = newXMLIssue.childNodes[0];
because it causes an error to have the function on the left side of the equation. I also tried:
var x = clientXML.querySelector("[id=XMLIssue-9]");
x = newXMLIssue.childNodes[0];
but this only changes a copy of the element.
You have to call replaceChild
on the parent:
var parent = clientXML.querySelector("[id=XMLIssue-9]");
parent.replaceChild(parent.childNodes[0], parent.childNodes[2]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.