首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

android上对xml的解析

2012-09-01 
android下对xml的解析android 解析xml1.使用SAXParser// TODO: switch to saxXmlPullParser xpp Xml.new

android下对xml的解析
android 解析xml
1.使用SAXParser

       // TODO: switch to sax        XmlPullParser xpp = Xml.newPullParser();        xpp.setInput(in, null);  // null = default to UTF-8        int eventType;        String title = "";        String link = "";        String description = "";        eventType = xpp.getEventType();        while (eventType != XmlPullParser.END_DOCUMENT) {            if (eventType == XmlPullParser.START_TAG) {                String tag = xpp.getName();                if (tag.equals("item")) {                    title = link = description = "";                } else if (tag.equals("title")) {                    xpp.next(); // Skip to next element -- assume text is directly inside the tag                    title = xpp.getText();                } else if (tag.equals("link")) {                    xpp.next();                    link = xpp.getText();                } else if (tag.equals("description")) {                    xpp.next();                    description = xpp.getText();                }            } else if (eventType == XmlPullParser.END_TAG) {                // We have a comlete item -- post it back to the UI                // using the mHandler (necessary because we are not                // running on the UI thread).                String tag = xpp.getName();                if (tag.equals("item")) {                    RssItem item = new RssItem(title, link, description);                    mHandler.post(new ItemAdder(item));                }            }            eventType = xpp.next();        }

热点排行