Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
Unable to appendChild more than once with Parent Node in XML (Javascript)

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)
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda