62,614
社区成员
发帖
与我相关
我的任务
分享
public class Test {
public static void main(String[] args) {
try {
File fi = new File("c:\\test.xml");
SAXBuilder sb = new SAXBuilder(false);
Document doc = sb.build(fi);
Test test = new Test();
test.doElement(doc.getRootElement());
XMLOutputter xmlOut = new XMLOutputter();
Format format;
format = Format.getPrettyFormat();
format.setEncoding("UTF-8");
format.setOmitDeclaration(!true);
format.setLineSeparator("\n");
xmlOut.setFormat(format);
FileOutputStream fos = new FileOutputStream("c:\\test2.xml");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, "UTF8"));
xmlOut.output(doc, bw);
bw.flush();
bw.close();
} catch (Exception e) {
}
}
protected void doElement(Element element) {
String temp = element.getName();
System.out.println(temp);
Iterator attributes = (element.getAttributes()).iterator();
while (attributes.hasNext()) {
Attribute attribute = ((Attribute) (attributes.next()));
attribute.setValue("aaaa");
}
}
}