//获取xml序列化器
XmlSerializer xs = Xml.newSerializer();
File file = new File("sdcard/sms2.xml");
FileOutputStream fos;
try {
fos = new FileOutputStream(file);
//初始化
//xml文件中什么编码生成
xs.setOutput(fos, "utf-8");
//开始生成xml文件
//生成头结点
xs.startDocument("utf-8", true);
//生成开始标签
xs.startTag(null, "smss");
for (Sms sms : smsList) {
xs.startTag(null, "sms");
xs.startTag(null, "body");
xs.text(sms.getBody() + "<body>");
xs.endTag(null, "body");
xs.startTag(null, "type");
xs.text(sms.getType() + "");
xs.endTag(null, "type");
xs.startTag(null, "date");
xs.text(sms.getDate() + "");
xs.endTag(null, "date");
xs.startTag(null, "address");
xs.text(sms.getAddress());
xs.endTag(null, "address");
xs.endTag(null, "sms");
}
//生成结束标签
xs.endTag(null, "smss");
//告知序列化器生成xml结束
xs.endDocument();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
//注释:Sms是javaBean对象