pull解析XML文档
Xml代码
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book id="12">
<name>thinking in java</name>
<price>85.5</price>
</book>
<book id="15">
<name>Spring in Action</name>
<price>39.0</price>
</book>
</books>
public static readLocalXml throws Exception {
// 创建Pull解析
InputStream inputStream = getResources().openRawResource(R.raw.frist);
XmlPullParser pullParser= Xml.newPullParser();
// 解析XML
pullParser.setInput(inputStream, "utf-8");
// 开始
int eventType = pullParser.getEventType();
List<Book> books = null;
Book book = null;
while (eventType != XmlPullParser.END_DOCUMENT) {
String nodeName = pullParser.getName();
switch (eventType) {
// 文档开始
case XmlPullParser.START_DOCUMENT:
相关新闻>>
- 发表评论
-
- 最新评论 更多>>