使用XML序列化对象创建XML文件
前端之家收集整理的这篇文章主要介绍了
使用XML序列化对象创建XML文件,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
XmlSerializer xs = Xml.newSerializer();//拿到序列化对象 File file = new File(路径); FileOutputStream fos = new FileOutputStream(file); xs.setOutput(fos,"utf-8"); xs.startDocument("utf-8",true); xs.startTag(null,"message"); //遍历短信对象 for(Message message:smsList){ xs.startTag(null,"sms"); xs.startTag(null,"body"); xs.text(message.getBody()); xs.endTag(null,"body"); s.startTag(null,"date"); xs.text(message.getDate()); s.endTag(null,"date"); xs.startTag(null,"address"); xs.text(message.getAddress()); s.endTag(null,"address"); xs.startTag(null,"type"); xs.text(message.getType()); xs.endTag(null,"type"); xs.endTag(null,"sms"); } xs.endTag(null,"message"); xs.endDocument(); 原文链接:https://www.f2er.com/xml/295285.html