• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Recusively removing branches

 
justin mcsporran
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an xml document from which I'd like to select an element and then remove all of it's children, it's children's children, and so on...(ie: recursively).
I'm fine with the selecting (I'm using dom4j's XPath support for that), but I can't find a method to call on a Node to do the recursive removal. Should there be one in dom4j or will I have to use some kind of treewalk algorithm to seek out each child Node and delete it?
The only single method-based possiblity seemed to be Node's detach() method, but the dom4j javadocs don't detail whether this is recursive or not. Also, the nomenclature's a bit confusing (ie: is detaching the same as deleting?).
Anyway, many thanks in advance for any assistance from the assembled brains.
Bests,
Justin
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not clear on why just detaching the first level of children is not sufficient. Unless there are other links floating around somewhere, seems to me that the dependent nodes should be automatically GCed.
Bill
 
justin mcsporran
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Will,
Thanks for the reply.
I just wasn't sure if detach() would do that or not. Are you saying for sure that detach() removes all child nodes below the node being detached, and doesn't just orphan them somehow?
Cheers,
Justin
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't matter what the internal links are within the child nodes - if the only reference connected to a running Thread has been removed, all those objects are eligible for GC.
I'm assuming you are not keeping any other links to the detached nodes.
Bill
 
justin mcsporran
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for the help.
Cheers,
Justin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic