android XmlSerializer使用
1)首先要用XML静态类得到实例
XmlSerializer xs = Xml.newSerializer();
2)然后new文件,指定输出路径
File file = new File(getFilesDir(),"xmlSerializer.xml"); FileOutputStream fos = null; try { fos = new FileOutputStream(file);
xs.setOutput(fos,"utf-8");
3)然后开始写文件的开始和结尾,根标签的开始和结尾
xs.startDocument("utf-8", true); xs.startTag(null, "msg"); //... xs.endTag(null, "msg"); xs.endDocument();
4)在上面省略的地方写标签和值
xs.startTag(null, "id"); xs.text(m.getId()+""); xs.endTag(null, "id");
5)最后记住fos.close();