导包就不导了,dom4j平时用的也比较多,就简单的封装了一下。
public class Dom4jPath {
public static final String PATH = "src/p1.xml";
public static Document getDocument(String path){
try{
SAXReader r = new SAXReader();
Document d = r.read(path);
return d;
}catch(Exception e){
e.printStackTrace();
}
return null;
}
public static void getFormat(String path,Document document){
try{
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(
new FileOutputStream(path),format);
writer.write(document);
writer.close();
}catch(Exception e){
e.printStackTrace();
}
}
}