[jdom-interest] JDOM && Jaxen

Jason Hunter jhunter at acm.org
Wed Aug 1 12:47:22 PDT 2001

> > bob mcwhirter wrote:
> > >
> > > Yah, even without getParent(), though, not using flyweights on the
> > > Namespaces would help.
> >
> > Really, why?
> <foo>
>         <bar xmlns:cheese="http://cheese.org/"/>
>         <bar xmlns:cheese="http://cheese.org/"/>
> </foo>
> This document has 2 namespace nodes, but that's represented
> in JDOM as only a single Namespace object, due to fly-weighting.
> Thus, this xpath
>         count(//namespace::*)
> should return 2, but for JDOM, only returns 1.

XPath was clearly created with DOM in mind and without much regard to
other potential object models, and as a result providing XPath support
in other object models drives the models to approach DOM in look and

In the abstract sense, counting namespace declarations is a relatively
useless query because it says nothing about the semantics of the
document but only tells you about one arbitrary textual representation.

Back to reality: eliminating flyweights doesn't solve this problem
because Namespaces in JDOM are treated as simple immutable data holders
(they way they should be treated) and so you can use the same Namespace
instance for the two "bar" elements above and you'll still get 1 as your

Of course, you can determine the right answer without parentage. 
XMLOutputter has the ability already to put the namespace decls where
they belong.  It requires using a namespace stack to track what's in the
hierarchy when examining an element.  It makes moving elements fast and
easy and reliable (since their namespaces won't change as a result of
placements) but makes output have to do a bit more examination to
determine where decls are to be placed.

Is any of this helpful?  :-)


More information about the jdom-interest mailing list