wood burning stoves*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: removing node DOM