[jdom-interest] detach() from element

kandryc at miser.umass.edu kandryc at miser.umass.edu
Tue Mar 22 15:08:41 PST 2005


I have an XML file structured something like the following:

<my-lists>
   <list refid="1" date="3/22/2005 4:09 PM" />
   <list refid="1" date="3/22/2005 4:14 PM" />
   <list refid="1" date="3/22/2005 5:19 PM" /> 
   <list refid="1" date="3/22/2005 6:01 PM" />
   <list refid="2" date="3/22/2005 6:23 PM" /> 
</my-lists>

However, when I execute the following code:

List my_lists = theDocument.getRootElement().getChildren();
for (int i = 0; i < my_lists.size(); i++) {
   Element next = (Element)my)lists.get(i);
      if (next.getAttribute("refid").getValue().equals("1")) {
         next.detach();
      }
}

The output XML is:

<my-lists>
   <list refid="1" date="3/22/2005 4:14 PM" />
   <list refid="1" date="3/22/2005 6:01 PM" />
   <list refid="2" date="3/22/2005 6:23 PM" /> 
</my-lists>

Why are not all the elements with refid="1" not detached?


More information about the jdom-interest mailing list