/*读*/
SAXBuilder builder = new SAXBuilder();
Document doc = null;
try {
doc = builder.build("config.xml");
} catch (Exception e) {
e.printStackTrace();
return;
}
//获得这个文档的根元素
Element printer = doc.getRootElement();
Element name = printer.getChild("name");
this.name = name.getText();
/*写*/
SAXBuilder builder = new SAXBuilder();
Document doc;
try {
doc = builder.build("config.xml");
} catch (Exception e) {
return;
}
Element printer = doc.getRootElement();
Element name = printer.getChild("name");
name.setText( PrintParameter.getInstance().getName() );
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setEncoding("utf-8"));
try {
outputter.output(doc, new java.io.FileOutputStream("config.xml"));
} catch (Exception e) {
}