android 用Pull 创建XML
16lz
2022-06-19
保存代码:
/** * 保存数据到XML文件中 * @param persons * @param out * @throws Exception */public void save(List<person> persons,OutputStream out) throws Exception{ XmlSerializer ser=Xml.newSerializer(); ser.setOutput(out, "UTF-8"); ser.startDocument("UTF-8",true); //主信息 ser.startTag(null, "persons"); for(person item: persons) { //明细信息 ser.startTag(null, "person"); ser.attribute(null,"id",String.valueOf(item.getId())); //Name ser.startTag(null, "name"); ser.text(item.getName()); ser.endTag(null, "name"); //age ser.startTag(null, "age"); ser.text(item.getName()); ser.endTag(null, "age"); ser.endTag(null, "person"); } ser.endTag(null, "persons");ser.endDocument();out.flush();out.close();}
调用方法:
/** * 信息写入XML中 * @param p * @throws Exception */private void outXml() throws Exception{
personservice p=new personservice();List<person> pl=new ArrayList<person>();
pl.add(new person(43,"zhangxx",80));
pl.add(new person(12,"lili",20));
pl.add(new person(78,"xiaoxiao",8));
File xmlFile=new File(this.getFilesDir(),"itcast.xml");
FileOutputStream out=new FileOutputStream(xmlFile);
p.save(pl, out);
}
更多相关文章
- Android(安卓)模拟登陆 保存密码(信息)到手机中 文件信息读取
- Monkey测试结果解析(二)
- Android积木之图片的生成和保存
- iOS、Android获取文件头信息
- 获取android系统信息或应用程序信息
- android 修改系统显示u盘的名称
- 【Android】向sdcard中写入文件
- android studio的安装信息
- Android(安卓)source code[ 源代码]下载,问题和解决办法