Hi All,

I'm using dom4j1.6.
I need to sort child elements returned by the the elements() method using an external Comparator.
However this returns a BackedList. When sorted its set() method calls addNode() and removeNode() which throw Exceptions as the node's parent is already defined.
Currently I get around it like this:


public List getOrderedChildren( Element parent ) {
  List backedList = parent.elements();
  if ( !backedList.isEmpty() ) {
    List children = new ArrayList( backedList );
    Collections.sort( children, myComparator );
    return children;
  }
  return Collections.EMPTY_LIST;
}

Has anyone any better ideas that do not involve the instantiation of an additional ArrayList every time?

Many thanks,

Mike E.

--
Mike Evans
Incremental Ltd.
www.incremental.eu.com



-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to