标签:
首先获得一个XmlSerializer序列化对象
XmlSerializer serializer = new Xml.newSerializer();
使用XmlSerializer生成一个XML文件;
serializer.setOutput(aa.xml,"utf-8")
serializer.startDocument("utf-8",true)//设置头文档serializer.startTag(null,"person")//设置键值对
serializer.text("张三")//设置内容
serializer.endTag(null,"person")
serializer.startTag(null,"person")//设置键值对
serializer.text("李四")//设置内容
serializer.endTag(null,"person")
serializer.startDocument()
serializer.commit();
获得一个SharedPreferences序列化对象
SharedPreferences sp = context.getSharedPreferences("XML的名称",模式)
获得一个编辑器
Editor edit = sp.edit();
edit.putString("UserName","hahaha");//设置键值对
edit.putString("PassWord","123123")//
edit.commit();//提交
解析步骤:
XmlPullPaser parser = Xml.newPullParser();
while(type!=XmlPullParser.END_DOCUMENT)
{
if(type==XmlPullParser.START_TAG)
{
if(键值名.equals(parser.getName))
{
String str = parser.netText();
}else if(键值名.equals(parser.getName))
{
String str = parser.netText();
}else if(键值名.equals(parser.getName))
{
String str = parser.netText();
}
}
type = parser.next();
}
标签:
原文地址:http://www.cnblogs.com/guoxiansheng/p/5671696.html