JODM解析xml主要涉及创建Document对象:Document doc = saxbuilder.build("xml_path");
添加xml各节点就不写了
输出:
XMLOutputter outputter = new XMLOutputter();
Format fmat = Format.getPrettyFormat();//设定输出格式
fmat.setEncoding("gb2312");
fmat.setIndent(" ");
outputter.setFormat(fmat);
outputter.output(doc, System.out);
如果需要生成一个xml文件则将红字部分替换为
// xmlOut.output(doc, new FileWriter("student1.xml"));或
// xmlOut.output(doc, new FileOutputStream("student3.xml"));