Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

285
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda