wood burning stoves*
The moose likes XML and Related Technologies and the fly likes Deleting child nodes from an xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Deleting child nodes from an xml" Watch "Deleting child nodes from an xml" New topic
Author

Deleting child nodes from an xml

reggie rui
Greenhorn

Joined: Feb 10, 2009
Posts: 3
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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
Sharad Khanna
Greenhorn

Joined: Mar 19, 2010
Posts: 3
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


Sharad
checkout http://www.hamaraguru.com for Salaries and Reviews for Indian Companies
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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
s ithu
Greenhorn

Joined: Apr 10, 2012
Posts: 11
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Deleting child nodes from an xml
 
Similar Threads
example of where exists
retrieving object hierarchy - many-to-one?
Question on Super
Parent child join query
Overriding/overloading