Terry, Not sure how you're getting the "<>" results. Here's a little test program that works as I think you're looking for. However, I did discover the code that's commented out to give a java.util.ConcurrentModificationException, since I was attempting to modify the list while iterating through it. Don't think that is causing you problems since you stated you were getting the list printed out.
HTH steve import org.dom4j.*; import org.dom4j.io.*; import java.util.*; import java.io.*; public class TestRemoveElement { public TestRemoveElement() {} public void run() { // create body element with para children Element body = DocumentHelper.createElement("body"); for (int i=0;i<10;i++) { Element para = DocumentHelper.createElement("para"); para.setText("I'm para " + Integer.toString(i)); body.add(para); } System.out.println(body.asXML()); // now remove, say 4 and 7 // Iterator it1 = body.elementIterator("para"); // while ( it1.hasNext() ) { // Element pe = (Element)it1.next(); // String text = pe.getText(); // if ( text.endsWith("4") || text.endsWith("7") ) // body.remove(pe); // } // System.out.println(body.asXML()); // now remove, say 4 and 7 List paras = body.elements("para"); body.remove((Element)paras.get(4)); body.remove((Element)paras.get(7)); System.out.println(body.asXML()); writeElement(body); } private void writeElement(Element ele) { try { XMLWriter xml = new XMLWriter(new FileWriter("test.xml")); xml.write(ele); xml.close(); } catch(IOException ioe) { ioe.printStackTrace(System.out); } } public static void main(String[] args) { TestRemoveElement tre = new TestRemoveElement(); tre.run(); } } Terry Steichen wrote: > Hi, I'm trying to strip out some erroneous 'para' elements (under a > parent 'body' element) from an XML file and write out the corrected > version. What I'm doing is getting the list of 'para' elements from > its parent element 'body', iterating through the 'para' elements with > various checks. When I find a bad one, I call (pseudo code) > BodyElement.remove(BadParaElement). To check whether it worked, I then > produce a new listing of 'para' elements. This listing shows that all > the erroneous ones have been removed, while the 'good' ones have been > retained. However, when I try to write out a new version of the XML > file (using XMLWriter) I end up with an XML file in which all 'para' > elements that contain only "<>". The file has the correct number of > 'para' elements, and all the other elements are correct. I'm sure I'm > overlooking something simple and I'd appreciate some insight as to > what that might be. Regards, Terry ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user