[jdom-interest] Important proposal: Element/Document changes

Jools Enticknap jools at jools.org
Thu Jul 27 15:07:54 PDT 2000


On Thu, 27 Jul 2000, Jason Hunter wrote:

> > I was under the impression that setRootElement() was going due to the
> > problems involved in making it behave ?
> 
> Problems behaving?

<quote>
The issue is how you do a document like this:

<!-- comment -->
<root/>
<!-- comment -->

It's a whole lot easier with the above using addContent(Element) than
trying to make setRootElement() behave right.  If you
addContent(Element) and there's already an element, then we throw an
IllegalAddEx.

</quote>

Which is what I was refering to.

> 
> > So to summarize;
> > 
> > Do we need two methods for setting the Root element of a Document ?
> 
> Well, which would you remove?
> 

Fruedian slip there I think, I was not advocating the removal of either,
rather I wanted to clarify their use and see if we need two.

I personally think there is a need for them both(now that supprised you
did'nt it !) 

I would use the setContent(<type>) methods for creating the initial layout
of the Document, and if I needed to replace __just__ the root I could call
setRootElement() and I'd know that the Document would still be as I
intended it.

For instance;

Imagine that I want to have a Document which has copyright information
before and afer the root Element.

<!-- Copyright Nmemonix Ltd 2000 -->
<root/>
<!-- Copyright Nmemonix Ltd 2000 -->

I could use the following method to make sure that all the documents were
written out with Copy right information as a header and tailer.

void dumpDocuments(Document doc, Vector elems) {

	Enumeration e = elems.elements();

	while(e.hasMoreElements()) {
		Element elem = (Element) e.nextElement();
		
		doc.setRootElement(elem);
		dumpDocument(doc);
	}

}


But in order to create the Document in the first place I would want to
specify the order of the Comments and the place holder root Element by
using setContent() in the order in which I would want them to appear in
the Document.

	doc.setContent(comment);
	doc.setContent(new Element("root"));
	doc.setContent(comment);


So there might be a reason to have both.

Comments ?


--Jools




> -jh-
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> 




More information about the jdom-interest mailing list