how to remove nodes from an xml file with javascript?

Asked

Viewed 124 times

0

I have an xml document, a script.js and an html page where the following test should occur,I click on a button on the page and a function should be executed in the script that removes a group of nodes from the xml file,follow it below

FILE.XML

<?xml version="1.0" encoding="utf-8"?>
<filmes>
<filme>
  <titulo>A Casa Branca</titulo>
  <genero>comédia</genero>
  <ano>1999</ano>
  <faixaEtaria>+10</faixaEtaria>
</filme>
<filme>
  <titulo>A casa monstro</titulo>
  <genero>animação</genero>
  <ano>2007</ano>
  <faixaEtaria>+10</faixaEtaria>
</filme>
<filme>
  <titulo>O grito</titulo>
  <genero>terror/suspense</genero>
  <ano>2003</ano>
  <faixaEtaria>+14</faixaEtaria>
</filme>
<filme>
  <titulo>Pânico</titulo>
  <genero>suspense</genero>
  <ano>2006</ano>
  <faixaEtaria>+14</faixaEtaria>
</filme>
</filmes>

And when I click on the page button,it should remove the first group of nodes from the movie node,consequently the code will look like this

<?xml version="1.0" encoding="utf-8"?>
<filmes>
  <titulo>A casa monstro</titulo>
  <genero>animação</genero>
  <ano>2007</ano>
  <faixaEtaria>+10</faixaEtaria>
</filme>
<filme>
  <titulo>O grito</titulo>
  <genero>terror/suspense</genero>
  <ano>2003</ano>
  <faixaEtaria>+14</faixaEtaria>
</filme>
<filme>
  <titulo>Pânico</titulo>
  <genero>suspense</genero>
  <ano>2006</ano>
  <faixaEtaria>+14</faixaEtaria>
</filme>
</filmes>

I’ve researched about removeChild but I can’t create a function that removes the nodes from the xml file, I really need help because I can’t find solutions for this,so any example of function that solves the problem will be very useful.

  • Do you want to remove from the file or read? I mean, rewrite the file without the node or just read and remove the node?

  • of the file, it serves as a data store in my project

  • that is, rewrite the file without the node

  • Vc uses PHP?......

  • use, however I am creating a hybrid mobile app and need to use JS functions, the app will fetch data from xml file.

  • To rewrite the vc file you need to use a server-side language such as PHP.

  • OK,but what about with JSON? It is possible for me to change and remove values in json code with javascript?

  • Yes, it is possible.

  • Got it, thank you.

Show 4 more comments

1 answer

0

  • removeChild I’ve tried, but it only removes what’s on the screen and not from the xml file

Browser other questions tagged

You are not signed in. Login or sign up in order to post.