This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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
Joined: May 12, 2003
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
Author and all-around good cowpoke
Joined: Mar 22, 2000
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