/** * 往磁盘上写一个xml文件 * * <?xml version="1.0" encoding="UTF-8" standalone="true"?> //文档的神明 <persons> //标签tag <person id=“18"> //ID是person标签的一个属性 <name>allen</name> <age>36</age> </person> <person id=“28"> <name>james</name> <age>25</age> </person> </persons> * */ //XmlPullParser parser = Xml.newPullParser();// 解析xml XmlSerializer serializer = Xml.newSerializer();// xml序列化工具类 File f = new File(Environment.getExternalStorageDirectory(), "persons.xml"); try { FileOutputStream fos = new FileOutputStream(f); serializer.setOutput(fos, "utf-8");//给序列化工具设置输出路径和输出编码 serializer.startDocument("utf-8", true); serializer.startTag(null, "persons"); //person 标签 serializer.startTag(null, "person"); serializer.attribute(null, "id", "18"); serializer.startTag(null, "age"); serializer.text("lx"); serializer.endTag(null, "age"); serializer.endTag(null, "person"); serializer.endTag(null, "persons"); serializer.endDocument();