[jdom-interest] Problems by sorting the list (JDOM beginner)

Julien GROUTEAU sabela_julien_grouteau at yahoo.fr
Wed Mar 27 14:37:15 PST 2002

One thing I found useful, while sorting list of childrens, is to detach them
prior to any 'processing' on them.

So I would say :

List ch = root.getChildren;
Iterator it = ch.iterator ();
while (it.hasNext ()) {
	Element element = (Element) it.next ();
	element.detach ();
Collections.sort (ch , mycomp);

Hope this helps.


-----Message d'origine-----
De : jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]De la part de Galuc
Envoyé : mercredi 27 mars 2002 23:05
À : jdom-interest at jdom.org
Objet : [jdom-interest] Problems by sorting the list (JDOM beginner)


My problem is, I can't sort the List!
I use:
List ch = root.getChildren;
Collections.sort( ch , mycomp );

I wrote a comparator, what works.
But I got an exception:
org.jdom.IllegalAddException: The element already has an existing parent

I tried to search in the archive, but I couldn't find any solutions!

Thanks, Galuc

To control your jdom-interest membership:

Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

More information about the jdom-interest mailing list