This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

removing node DOM

 
Brandon Broschinsky
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic