如何在android中使用PullParser从xml获取标签和子标签的文本?

时间:2015-07-22 05:28:23

标签: android xmlpullparser

我必须从以下xml中获取银行名称,但在使用XMLPullParser时只能从中获取url。任何人都可以指导我成功地做到这一点吗?

    <option ident="1" bank_short="INB">
         Indian Bank
        <graphix>http://cdn-assk.com/gfx/inb.png</graphix>
                                </option>


{
                    XmlPullParserFactory factory = XmlPullParserFactory
                            .newInstance();
                    factory.setNamespaceAware(true);
                    XmlPullParser parser = factory.newPullParser();
                    parser.setInput(new StringReader(xml));
                    int eventType = parser.getEventType();
                    while (eventType != XmlPullParser.END_DOCUMENT) {
                        tagname = parser.getName();
                        switch (eventType) {
                        case XmlPullParser.START_TAG:
                            if (tagname.equalsIgnoreCase("option")) {
                                movie = new Movie();
                                movie.setAuct_Tag_Id(""
                                        + parser.getAttributeValue(0));
                                movie.setAuct_Tag_ItemNo(""
                                        + parser.getAttributeValue(1));
                            }
                            break;
                        case XmlPullParser.TEXT:
                            text = parser.getText();
                            break;
                        case XmlPullParser.END_TAG:
                                if (tagname.equalsIgnoreCase("option")) {
                                    movie.setTitle(text);
                                    movieList.add(movie);
                                } else if (tagname.equalsIgnoreCase("graphix")) {
                                    movie.setThumbnailUrl(text);
                                }

提前多多谢意。 :)

0 个答案:

没有答案