[jdom-interest] How do I re-order child elements?
thomas.nichols at iname.com
Tue May 15 07:32:36 PDT 2001
I need to re-order children of an Element. Since el.addContent() always
seems to _append_, what's the best way to do this?
Method 1: use getMixedContent() to get a List, then el.removeChildren(),
then el.addContent() for the Elements from the List.
Element newEl = el.clone();
newEl.addContent ( /* from el.getChildren().iterator() */ );
Then copy everything back from newEl to el.
Neither looks very attractive, nor efficient - I'd guess method 2 would be
a dog. Anyone have any better suggestions?
Would there be a more general use for an Element.addContent (int index,
Element content) ? This would allow plenty of scope for re-ordering and
sorting at minimal (apparent) cost, and would only need passing down to
LinkedList.add (int index, Object o). To reposition an element, just
el.addContent (index, child);
What do you think? Do other people have this requirement?
More information about the jdom-interest