第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

pull解析xml文件的實(shí)現(xiàn)與應(yīng)用

標(biāo)簽:
Android

1.解析的文件read.xml

[代码]xml代码:

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

<!--?xml version="1.0"   encoding="UTF-8"?-->

<books>

    <time level="1">

        <book   id="10086">C语言程序与设计</book>

        <book   id="10010">Java通史</book>

        <book   id="10055">C++进阶宝典</book>

        <book   id="10089">Swift入门与实践</book>

    </time>

    <time level="2">

        <book   id="10090">教你怎么不生气</book>

        <book   id="10005">佛经</book>

        <book   id="10095">老子</book>

        <book   id="10389">沉默的愤怒</book>

    </time>

    <time level="3">

        <book   id="10000">腰间盘突出日常防护</book>

        <book   id="10023">保护视力从点滴开始</book>

        <book   id="10011">颈椎病康复指南</book>

        <book   id="10013">心脏病的预防与防治</book>

        <book   id="10018">高血压降压宝典</book>

        <book   id="10019">强迫症的自我恢复</book>

        <book   id="10028">精神病症状学</book>

    </time>

    <time level="4">

        <book   id="12086">活着</book>

        <book   id="16010">生命的意义</book>

    </time>

    <time level="5">

        <book   id="12345">埋葬地理的风水学</book>

        <book   id="10329">遗书及财产分配学</book>

    </time>

</books>

 

2.Book类的创建

[代码]java代码:

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

package demo05;

 

public class Book {

    private int id;

    private String name;

    public int getId() {

        return id;

    }

    public void setId(int id) {

        this.id   = id;

    }

    public String getName() {

        return name;

    }

    public void setName(String   name) {

        this.name   = name;

    }

    @Override

    public String toString() {

        return "Book   [id=" + id + ", name=" + name + "]";

    }

     

}

 

3.解析类

[代码]java代码:

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

package demo05;

 

import java.io.FileInputStream;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

import java.util.Set;

 

import org.xmlpull.v1.XmlPullParser;

import org.xmlpull.v1.XmlPullParserException;

import org.xmlpull.v1.XmlPullParserFactory;

 

public class PullParse {

 

     

 

    public static void main(String[]   args) throws Exception {

             

        XmlPullParserFactory   factory=XmlPullParserFactory.newInstance();

        XmlPullParser   parser=factory.newPullParser();

        parser.setInput(new   FileInputStream("db/read.xml"),"UTF-8");

        int event=parser.getEventType();

        String   tag=null;

        Book   book=null;

        HashMap<integer,list<book>>map=null;

         List<book>list=null;

        while(event!=XmlPullParser.END_DOCUMENT){

             switch   (event) {

                case   XmlPullParser.START_DOCUMENT:

                    map=new   HashMap<integer, list<book="">>();

                    break;

                case   XmlPullParser.START_TAG:

                    tag=parser.getName();

                    if("time".equals(tag)){

                        String   level=parser.getAttributeValue("","level");

                        list=new   ArrayList<book>();

                        map.put(Integer.parseInt(level),list);

                    }

                    if("book".equals(tag)){

                        book=new   Book();

                        String   id=parser.getAttributeValue("","id");

                        book.setId(Integer.parseInt(id));

                    }

                    break;

                case   XmlPullParser.TEXT:

                    if("book".equals(tag)){

                        book.setName(parser.getText());

                    }

                 

                    break;

                case   XmlPullParser.END_TAG:

                    tag=null;

                    if("book".equals(parser.getName())){

                        list.add(book);

                    }

             

                    break;

            }

             event=parser.next();

        }

     

        Set<integer>set=map.keySet();

         for(Integer   in:set){

             System.out.println(in);

             for(Book   b:map.get(in)){

                 System.out.println(b);

             }

         }

    }

 

 

     

}</integer></book></integer,></book></integer,list<book>

 

原文链接:http://www.apkbus.com/blog-813041-61003.html

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消