I think the problem is that you are creating a List containing a List,
rather than a List of Elements.
Are you trying to retain all chldren whose name matches one of the names in
aNameList? If so how about doing it like this:-
public void deleteChildren(List aNameList) {
int size = aNameList.size();
List listToRetain = new ArrayList(size);
for ( int i = 0; i < size; i++) {
String name = aNameList.get(i);
List elements = this.root.elements( name );
listToRetain.addAll( elements );
}
// now listToRetain is a list of all elements that match one
// of the given names
root.elements().retainAll( listToRetain );
}
I've not tested this though. If you're getting strange behaviour, why not
add a JUnit test case and we can try figure out whats going wrong.
James
----- Original Message -----
From: "Tobias Rademacher" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 19, 2001 12:15 PM
Subject: [dom4j-user] Collection.retainAll(...) and dom4j Elements
> Hi,
>
> I've tried to get reatinAll(...) working with dom4j and I have problems.
> Consider the following code:
>
> public void deleteChildren(List aNameList) {
>
> List listToRetain = new ArrayList(aNameList.size());
>
> for (int i=0; i < aNameList.size(); i++) {
> listToRetain.add(this.root.element((String)aNameList.get(i)));
> }
>
> this.root.content().retainAll(Collections.singletonList(listToRetain));
>
> }
>
> aNameList cotains the name of Elements as String. This code will complety
> deletes all child nodes of root element. I replaced content() with
elements()
> and got the same result.
> The method retainAll(...) works with equals() on java.lang.Object level.
> Therefore I experimentd with createCopy(...) in order to get a better
copy.
> This won't work (because it's a deep copy ?). Setting the parent of such a
> clone by yourself have no effect.
>
> Any ideas to get this working?
>
> Thanks
>
> Toby
>
> --
> GMX - Die Kommunikationsplattform im Internet.
> http://www.gmx.net
>
> --
> GMX Tipp:
>
> Machen Sie Ihr Hobby zu Geld bei unserem Partner 1&1!
> http://profiseller.de/info/index.php3?ac=OM.PS.PS003K00596T0409a
>
>
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/dom4j-user
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dom4j-user