import java.lang.*; import java.io.*; import java.util.*; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; import org.jdom.*; public class Speed { public static Document getDoc(String fin)throws Exception { SAXBuilder builder = new SAXBuilder(false); Document jd = builder.build(new File(fin)); return jd; } public static Document saveDoc(Document doc,String fout)throws Exception { XMLOutputter outputter = new XMLOutputter(); FileOutputStream fous = new FileOutputStream(fout); outputter.output(doc,fous); fous.close(); return doc; } public static void test() { try{ Document xml = getDoc("poem_gen.xml"); Element root = xml.getRootElement(); Date dt = new Date(); System.out.println(dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds()); recursive(root); Date dt1 = new Date(); System.out.println(dt1.getHours()+":"+dt1.getMinutes()+":"+dt1.getSeconds()); saveDoc(xml,"x.xml"); }catch(Exception e){e.printStackTrace();} } public static void recursive(Element elem) { if(elem == null) { return; } // if(elem.getChild("par")!= null) // { // System.out.println("find par"); // del(elem); // } del(elem); //System.out.println(elem.getName()); List childList = elem.getChildren(); Iterator ii = childList.iterator(); while(ii.hasNext()) { Element e = (Element)ii.next(); recursive(e); } } public static void del(Element elem) { List parList = elem.getChildren(); Iterator i = parList.iterator(); while(i.hasNext()) { //System.out.println("del"); Element d = (Element)i.next(); if(d.getName().equals("par")) { i.remove(); elem.removeContent(d); } } } public static void main(String[] arg) { test(); } }