Buenos días,
Tengo dificultades para agregar un parentNode específico, por lo que básicamente cada vez que llamo dos veces al parentNode con appendChild, solo ejecuta el primer código appendChild. Sin embargo, necesito que funcionen juntos. Creé el mismo elemento dos veces pero también con diferentes nombres de variables. No estoy seguro de lo que está mal con eso ... ¡ayuda, gracias!
Ahora mismo solo hace esto..
<gmd:ParentNode> <gmd:onLine> <gmd:CI_OnlineResource> Partial Download Test </gmd:CI_OnlineResource> </gmd:onLine> </gmd:ParentNode>no puedo llegar a esto..
<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>Aquí está mi código para referencia
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) }