[jdom-interest] Moving elements

Alex Rosen arosen at novell.com
Fri May 2 06:44:18 PDT 2003


> Also, none of the JDOM objects implement Comparable. And how would
you
> implement one anyway? Are Text nodes < or > ProcessingIntruction
nodes,
> Comments, and Elements? 

Yup, good points. The user would have to supply their own Comparator to
sort the objects according to their needs.

Usually the user would either know what the content is before sorting,
or won't care whether comments etc. get moved around. Usually they'll
only care about sorting the Elements. If the document has whitespace for
formatting between the Elements then things get tricky. If it doesn't,
which is fairly common (because they're relying on XMLOutputter to do
the nice formatting for them), then writing a Comparator that sorts
Elements by whatever criteria you want is easy.

Come to think of it, if your document does have formatting whitespace
between your Elements, wouldn't sorting the result of getChildren() do
the right thing if we removed the IllegalAddException? I think it might
sort the Elements, but leave the whitespace Text nodes interspersed
between them, so the formatting still looks right. Maybe.

Alex




More information about the jdom-interest mailing list