//修改特定元素
try{
SAXReader saxReader = new SAXReader();
Document document = saxReader.read(new File("c:/lbm.xml"));
List list = document.selectNodes("//spring1/@publisher" );
Iterator iter=list.iterator();
while(iter.hasNext()){
Attribute attribute=(Attribute)iter.next();
if(attribute.getValue().equals("lbm"))
attribute.setValue("libaoming");
}
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("gbk");
XMLWriter output = new XMLWriter( new FileWriter(new File("c:/libaoming.xml")),format);
output.write( document );
output.close();
}
catch(Exception e) {
System.out.println(e.getMessage());
}
System.out.print("complent");