XML写入
2015-10-23 17:13
246 查看
private void createXml() throws IOException { ArrayList<People> arrayList = new ArrayList<People>(); for (int i = 0; i < 10; i++) { People p = new People("jim" + i, i); arrayList.add(p); } XmlSerializer xml = Xml.newSerializer(); OutputStream os = openFileOutput("peoples.xml", Context.MODE_PRIVATE); xml.setOutput(os, "utf-8"); xml.startDocument("utf-8", true); xml.startTag(null, "peoples"); for (People people : arrayList) { xml.startTag(null, "people"); xml.startTag(null, "name"); xml.attribute(null, "id", "1000"); xml.text(people.getName()); xml.endTag(null, "name"); xml.startTag(null, "age"); xml.text(String.valueOf(people.getAge())); xml.endTag(null, "age"); xml.endTag(null, "people"); } xml.endTag(null, "peoples"); xml.endDocument(); }
class People { String name; int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public People(String name, int age) { this.name = name; this.age = age; } public People() { } }
相关文章推荐
- 记一次因磁盘块默认保留策略导致的数据库导入失败问题
- 记一次因磁盘块默认保留策略导致的数据库导入失败问题
- 查看nginx、php编译参数
- 关于在链表中用递归形式,求出链表中的最大值,及节点数和平均值的函数
- STL中allocator类
- VIM命令学习总结
- Android 事件传递
- 微软算法100题14 在排序数组中找到和为指定数的任意两个元素
- oracle 第16章 事务
- JS正则表达式验证账号、手机号、电话和邮箱
- 布局Layouts之LinearLayout线性布局
- Tomcat 7最大并发连接数的配置
- iOS开发中iOS小结
- 如何设置TextView控件的背景透明度和字体透明度
- iOS: #ifdef DEBUG
- java中UUID
- Thymeleaf基本知识
- LeetCode之Maximum Subarray
- http常见错误返回码解释
- Google面经,已拿到offer哦!