• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deleting child nodes from an xml

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following xml:



I want to delete the child depending on the "name" attribute. Is there a way to do this ? i tried to do this with DOM but didnt work. Also, i can get the specific child node using XPath. But then again, how do i delete it from the xml ?

Thanks in Advance
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you look in the API documentation for the Node interface of DOM, you surely will find a method which deletes, or perhaps removes, a Node. Just scan down the list of methods until you find it. You would use that method once you have a reference to the node.

If you are still stuck, post your code and let's discuss it.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will need to parse the XML using either jdom or java.xpath libraries and delete the node.



reggie rui wrote:I have the following xml:



I want to delete the child depending on the "name" attribute. Is there a way to do this ? i tried to do this with DOM but didnt work. Also, i can get the specific child node using XPath. But then again, how do i delete it from the xml ?

Thanks in Advance

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i tried to do this with DOM but didnt work.




Why do people make statements like that and expect help

What is the code you wrote? What happened when you ran it?

You do realize that having modified the DOM in memory you still need to write it to a file, right?

Bill
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic