• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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
 
Sheriff
Posts: 28398
100
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic