This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes removing node DOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "removing node DOM" Watch "removing node DOM" New topic
Author

removing node DOM

Brandon Broschinsky
Ranch Hand

Joined: Aug 21, 2004
Posts: 41
In my program i am using DOM model. I have it set up to remove a node and all it's children which it does. The problem is it leaves a tag when it's done. For example I have a node <entry>..children..<entry> when i remove the entry and it's children, when i write the tree to a file it leaves a node with no children as <entry/> I am not sure why. He is my code to remove the node.

Node current= currentEntry;
System.out.println(current.getNodeName().toString());
while(current.hasChildNodes()){
current.removeChild(current.getFirstChild());
}

currentEntry is the current node that i am on in my tree.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Originally posted by Brandon Broschinsky:
In my program i am using DOM model. I have it set up to remove a node and all it's children which it does. The problem is it leaves a tag when it's done. For example I have a node <entry>..children..<entry> when i remove the entry and it's children, when i write the tree to a file it leaves a node with no children as <entry/> I am not sure why. He is my code to remove the node.

Node current= currentEntry;
System.out.println(current.getNodeName().toString());
while(current.hasChildNodes()){
current.removeChild(current.getFirstChild());
}

currentEntry is the current node that i am on in my tree.


Isin't this because you are removing only the Child Nodes. If you want to remove this Node also (current), then



Haven't tested this but based on your description and the API, this is the closest thing I can suggest.
Thanks.

- m


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
 
 
subject: removing node DOM
 
Similar Threads
How to extract specific attribute value in DOM
XML DOM & children nodes
adding and removing elements from DOM in java
XML help
Access DOCTYPE in DOM