我正在使用XStream生成我的对象的xml文件。但是,xml文件中省略了版本和编码头,我不知道为什么。这是打印出xml文件的方法:
public static void personsToXML(ArrayList<Person> persons) throws FileNotFoundException {
PrintWriter pw = new PrintWriter(new File("someFilePath"));
XStream xstream = new XStream();
for (Person i : persons)
pw.print(xstream.toXML(i));
pw.close();
}
它输出xml就好了,但没有标题,如
<?xml version="1.0"?>
不存在。
谢谢!