/** * 使用XmlSerializer写出XML * @param users User集合 * @param out 输出流 * @throws IOException */ public void saveAllByXmlSerializer(List<User> users, OutputStream out) throws IOException { XmlSerializer serializer = Xml.newSerializer(); serializer.setOutput(out, "UTF-8"); serializer.startDocument("UTF-8", true); serializer.startTag(null, "users"); for (User user : users) { serializer.startTag(null, "user"); serializer.attribute(null, "id", user.getId().toString()); serializer.startTag(null, "name"); serializer.text(user.getName()); serializer.endTag(null, "name"); serializer.startTag(null, "age"); serializer.text(user.getAge().toString()); serializer.endTag(null, "age"); serializer.endTag(null, "user"); } serializer.endTag(null, "users"); serializer.endDocument(); }
Android使用Pull解析器解析XML文件
内容版权声明:除非注明,否则皆为本站原创文章。