This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm using dom4j to construct an XML document from a series of records. I need to be able to start searching the document at a particular place as I'm loading in the various elements. Once found, I need to be able to create a new element at that location. I've set up a series of records like so:
library.book "Miles Copperthwaith"
library.book.chapter "I Am Born"
Starting from an empty document, create the root element.
Set the context at the root
Cycle thru the elements, searching for the element starting at the current context.
If not found, create the element AT THAT POINT IN THE CONTEXT.
If found, set the context to that element and look for the next element, unless you are at the last element, in which case
you create the element at that point, the current context, and add the text.
It's simple, but you get the idea. How to set the current context, and create an element at the right place, using the current context?
I don't know what it means to "pass back an element by reference". You do have a reference to an element, if that's what you had in mind. But there's nothing unusual about that, because in Java you only ever have references to objects anyway. There's nothing special about objects generated by dom4j.