Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] removing element from document

John C Cartwright

2007-12-06

Replies:

Hello All,

I need to remove all the Elements from a Document who have a particular
attribute w/ a particular value. My first (unsuccessful) attempt was
Element#removeContent w/in an iterator loop which throws a
ConcurrentModificationException.

Can someone suggest to me the correct way to do this sort of thing?

Thanks!

-- john

     
      List features =
root.getChild("RESPONSE").getChild("FEATURES").getChildren("FEATURE");
      for (Iterator i=features.iterator();i.hasNext();) {
        feature = (Element) i.next();
        fields = feature.getChild("FIELDS").getChildren("FIELD");
        for (Iterator j=fields.iterator(); j.hasNext();) {
           field = (Element)j.next();
           if ("#SHAPE#".equals(field.getAttributeValue("name"))) {
              //throws ConcurrentModificationException
              feature.getChild("FIELDS").removeContent(field);
           }
        }        
      }

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.