<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2715.400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>When I try to sort a list of children with this
code:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> public Element getListSortedByString(Element
element) {<BR> <BR> try
{<BR> List list =
element.getChildren();<BR> Collections.sort(list,
new ContentTagComparator());<BR>
element.setChildren(list);<BR> }<BR>
catch(Exception e) {<BR>
e.printStackTrace(System.out);<BR> }<BR>
return element;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> public class ContentTagComparator implements
Comparator {<BR> <BR> public int
compare(Object o1,Object o2) {</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> String s1 =
((Element)o1).getText();<BR> String s2 =
((Element)o2).getText();<BR> int result =
s1.compareTo(s2);<BR> return
result;<BR> }</FONT></DIV>
<DIV><FONT face=Arial size=2><BR> }<BR></DIV></FONT>
<DIV><FONT face=Arial size=2>I get this exception at the end of
Collections.sort(list, new ContentTagComparator()); process:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>org.jdom.IllegalAddException: The element already
has an existing parent<BR> at
org.jdom.ContentList.add(ContentList.java:190)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> at
org.jdom.ContentList.add(ContentList.java:146)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> at
org.jdom.ContentList.set(ContentList.java:663)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> at
org.jdom.ContentList$FilterListIterator.set(ContentList.java:1150)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> at java.util.Collections.sort(Unknown
Source)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Is it a bug ?</FONT></DIV>
<DIV><FONT face=Arial size=2>Is there another way to sort elements content
?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thanks</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Marcel Heuzer</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>