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

204
Visualizações
Remove child node from XML using JavaScript

I am getting some extra node in XML file which need to removed. I can do this simply using XSLT or Map though I want to achieve it using JavaScript. I want to remove the entire <Distributors> and <Location> node from input xml.

Input XML,

<bookstore>
    <book category="cooking">
        <title lang="en">Everyday Italian</title>
        <author>Giada De Laurentiis</author>
        <year>2005</year>
        <price>30.00</price>
    </book>
    <book category="children">
        <title lang="en">Harry Potter</title>
        <author>J K. Rowling</author>
        <year>2005</year>
        <price>29.99</price>
    </book>
    <Location>London</Location>
    <Year>2022</Year>
    <Distributors>
        <Distributor1>Ingram</Distributor1>
        <Distributor2>Amazon</Distributor2>
        <Distributor3>Company</Distributor3>
    </Distributors>
</bookstore>

Expected Output xml

<bookstore>
    <book category="cooking">
        <title lang="en">Everyday Italian</title>
        <author>Giada De Laurentiis</author>
        <year>2005</year>
        <price>30.00</price>
    </book>
    <book category="children">
        <title lang="en">Harry Potter</title>
        <author>J K. Rowling</author>
        <year>2005</year>
        <price>29.99</price>
    </book>
    <Year>2022</Year>
</bookstore>

I tried using DOM but using DOM it's consuming a lot of memory due to size of data. Is there any simple way to achieve it without much resources, otherwise I'll try to split the msg and then will check.

var xmlDoc = xml.responseXML;
var y = xmlDoc.getElementsByTagName("bookstore")[0];
var x = xmlDoc.documentElement.removeChild(y);

Need suggestion from experts here.

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