Good Day,
I am facing difficulties appending a specific parentNode, so basically whenever I call the parentNode with appendChild twice, it only runs the first appendChild code. However I need it to run together. I created the same element twice but with different variable names too. I am not sure what is wrong with it.. please do help thank you!
Right now it only does this..
<gmd:ParentNode>
<gmd:onLine>
<gmd:CI_OnlineResource>
Partial Download Test
</gmd:CI_OnlineResource>
</gmd:onLine>
</gmd:ParentNode>
I cannot get to this..
<gmd:ParentNode>
<gmd:onLine>
<gmd:CI_OnlineResource>
Partial Download Test
</gmd:CI_OnlineResource>
</gmd:onLine>
<gmd:onLine>
<gmd:CI_OnlineResource>
Full Download Test
</gmd:CI_OnlineResource>
</gmd:onLine>
</gmd:ParentNode>
Here is my code for reference
function test(){
xmlString = this.item.sys_xml_clob;
var metadataXmlString = jQuery.parseXML(xmlString);
//Parent Node
let newParentNode = metadataXmlString.getElementsByTagName("gmd:ParentNode")
//Creation of the Nodes
let newNode = metadataXmlString.createElement("gmd:onLine")
let newNode2 = metadataXmlString.createElement("gmd:CI_OnlineResource")
let partialDownload = metadataXmlString.createTextNode("Partial Download Test")
let oldNode = metadataXmlString.createElement("gmd:onLine")
let oldNode2 = metadataXmlString.createElement("gmd:CI_OnlineResource")
let fullDownload = metadataXmlString.createTextNode("Full Download Test")
//First Node to be Appended
newNode2.appendChild(partialDownload)
newNode.appendChild(newNode2)
newParentNode[0].appendChild(newNode)
//Second Node to be Appended
oldNode2.appendChild(fullDownload)
oldNode.appendChild(oldNode2)
newParentNode[0].appendChild(oldNode)
xmlString = (new XMLSerializer()).serializeToString(metadataXmlString);
console.log(xmlString)
}