使用Pull解析器生成XML文件
ile xmlFile = new File("person.xml");
FileOutputStream outStream = new FileOutputStream(xmlFile);
OutputStreamWriter outStreamWriter = new OutputStreamWriter(outStream, "UTF-8");
BufferedWriter writer = new BufferedWriter(outStreamWriter);
writeXML(persons, writer);
writer.flush();
writer.close();
如果只想得到生成的xml字符串内容,可以使用StringWriter:
StringWriter writer = new StringWriter();
writeXML(persons, writer);
String content = writer.toString();