Android利用pull解析器生成xml
来源:互联网 发布:淘宝直通车怎么找 编辑:程序博客网 时间:2024/09/21 09:04
doman类名为person.xml
package cn.itcast.doman;public class Person {private Integer id;private String name;private Integer age;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}}
生成xml方法类
public class XmlService {public static void save(List<Person> persons,OutputStream outputStream) throws Exception{XmlSerializer serializer = Xml.newSerializer();serializer.setOutput(outputStream, "utf-8");serializer.startDocument("UTF-8", true); //true表示生成单独文件serializer.startTag(null, "persons");for (Person person : persons) {serializer.startTag(null, "person");serializer.attribute(null, "id", person.getId().toString());serializer.startTag(null, "name");serializer.text(person.getName().toString());serializer.endTag(null, "name");serializer.startTag(null, "age");serializer.text(person.getAge().toString());serializer.endTag(null, "age");serializer.endTag(null, "person");}serializer.endTag(null, "persons");serializer.endDocument();outputStream.flush();outputStream.close();}}
测试类
public class TestXml extends AndroidTestCase{public void TestXmlOne() throws Exception{File file = new File(getContext().getFilesDir(), "Person.xml");OutputStream outputStream = new FileOutputStream(file);List<Person> persons = new ArrayList<Person>();Person person = new Person();person.setId(23);person.setName("li");person.setAge(21);persons.add(person);person = new Person();person.setId(27);person.setName("yuan");person.setAge(21);persons.add(person);XmlService.save(persons, outputStream);}}
- Android利用pull解析器生成xml
- android利用Pull解析器解析、生成XMl文件
- 如何利用Pull解析器生成XML
- android利用pull解析器解析xml
- android利用pull技术来解析和生成xml文件
- 利用Pull生成和解析xml文件
- android采用pull解析器解析和生成XML
- Android 采用Pull解析器解析和生成XML内容
- Android使用pull解析器解析和生成xml
- Android 利用PULL生成XML文档
- android中利用pull解析xml文件
- 利用pull解析器解析xml文件
- 利用pull解析Xml
- Xml利用Pull解析
- 在android中使用Pull解析器生成xml文件
- android基础--使用Pull解析器生成XML文件
- android(15)_使用Pull解析器生成XML文件
- Android笔记使用Pull解析器生成XML文件
- 黑马程序员---什么是对象?
- 黑马程序员---关于内存分配问题
- mysql命令
- Java网络编程
- UML之序列图
- Android利用pull解析器生成xml
- 基于TCP的ECHO程序
- 程序员面试题精选100题(51)-顺时针打印矩阵
- 如何设置span的width属性
- iOS内存警告
- linux系统调用和库函数调用的区别
- win7下笔记本做wifi热点
- 链表实现一个学生信息统计的功能
- eclipse 注意编码设置