[jdom-interest] How to ease traversal of JDOM tree
Hallvard Tratteberg
hal at idi.ntnu.no
Tue Nov 20 12:46:09 PST 2001
> -----Original Message-----
> Subject: Re: [jdom-interest] How to ease traversal of JDOM tree
>
> philip.nelson at omniresources.com wrote:
>
> > In addition, really nobody likes the idea of a
> > comment or PI having setContent or other methods that made no sense.
I completely agree, we should not try to make the leaf nodes into generic
nodes that seemingly can have content.
> Yet, I think this is interesting because it would allow to get rid of all
> these addContent(Xxx) methods in Element for only 2 methods
> (addContent(Node) and addContent(String)) and thus treat all types of
nodes
> equally, without resorting to instanceof tests.
Something in-between is defining two base classes, ContentNode and LeafNode.
ContentNode would contain code for addContent and getContent/getChildren
methods and will be the superclass of Document and Element. LeafNode would
contain the getParent method (which would have to be duplicated in Element)
and would be the superclass of PI, CDATA/Text, Comment, EntityRef etc. This
would simplify many things, both within JDOM and in the JDOM API.
Traversers would only have to test whether an object was a String, LeafNode
or (else) a ContentNode. It's simple, but shouldn't be simpler.
Hallvard
More information about the jdom-interest
mailing list