Android development learns to use XmlPullParser to parse xml files

There are three main ways to parse XML in Android: sax, dom and pull. For its content, please refer to: http://blog.csdn.net/liuhe688/article/details/6415593 This article will mainly introduce the pull parser to parse xml files, the environment is ubuntu 12.04+ intelij 13.1 + android sdk 2.1 1. Create an XML project, the steps are as follows: 2. Parse an xml file: assets/person.xml <?xml version=”1.0″ encoding=”UTF-8″?> persons person id=”1101″ nameamos</name age30</age </person person id=”1102″ nametom</name age18</age </person </persons com/amos/xml/domain/Person.java package com.amos.xml.domain; /** * Created by amosli on 14-6-3. */ public class Person { private String name; private Integer age; private Integer id; public Integer getAge() { return age; } public void setAge(Integer age) { if (age 100) { this.age = 0; } else { this.age = age; } } public Integer getId() { returnid; } public void setId(Integer id) { this.id =id; } public String getName() { returnname; } public void setName(String name) { this.name =name; } } com/amos/xml/service/PersonService.java package com.amos.xml.service; import android.content.Context; import android.content.res.AssetManager; import android.util.Log; import android.util.Xml; import com.amos.xml.domain.Person; import org.xmlpull.v1.XmlPullParser; importjava.io.InputStream; import java.util.ArrayList; importjava.util.List; /** * Created by amosli on 14-6-3. */ public class PersonService { private Context context; public PersonService(Context context) { this.cOntext= context; } /** * Convert the…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索