XMLSerializer
startDocument ("utf-8",true); 编码类型,是否独立
endDocument
XmlSerializer serializer= Xml.newSerializer();
serializer.setOutput(openFileOutput("smslist.xml",MODE_PRIVATE),"utf-8");//会在对应包下files/smslist.xml中输出。
serializer.startDocument("utf-8",true); //文档开始声明
serializer.startTag(null,"SMSList");//命名空间 , 标签名
for(SMS sms:smsList){
serializer.startTag(null,"SMS");
serializer.startTag(null,"from");
serializer.text(sms.from); //设置内容
serializer.endTag(null,"from");
serializer.startTag(null,"content");
serializer.text(sms.content);
serializer.endTag(null,"content");
serializer.startTag(null,"time");
serializer.text(sms.time);
serialize
r.endTag(null,"time");
serializer.endTag(null,"SMS");
}
serializer.endTag(null,"SMSList");//结束标签
serializer.endDocument();
序列化对象思路:Xml.newSerializer();->serializer.setOutput(openFileOutput("name.xml","utf-8");->serializer.startDocument("utf-8",true);->startTag(namespace,"tagname") ->serializer.text("content") ->endTag(namespace,"tagname");->endDocument();
反序列化的思路:用pull解析xml。
原文链接:https://www.f2er.com/xml/294447.html