  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | removing element from document | removing element from document 2007-12-06 - By John Cartwright
Back Sorry to reply to myself, but the following XPath approach seems to work - is the the recommended solution?
-- john
List nodesToDelete = XPath.selectNodes(root, "//FIELD[@(protected)='#SHAPE#']"); int size = nodesToDelete.size(); for (int i=0; i<size; i++){ ((Element)nodesToDelete.get(i)).detach(); }
John Cartwright wrote: > 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) __ ____ ____ ____ ____ ____ ____ ____ ____ ____ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
|
|
 |