XMLPullParser android不显示XML

时间:2013-06-26 10:02:47

标签: android xml-parsing

我正在尝试从android中的网址解析xml文件。但它没有显示

public static void load(Context mCtx) throws IOException, XmlPullParserException {
    if (areaList.size() <= 0) {
            processAreaList(mCtx, "http://staging.hpgue.com:8270/newiklaim/cities/xmlcity.xml");
    }

    if (stationMap.size() <= 0) {
        processStationList(mCtx, "http://staging.hpgue.com:8270/newiklaim/workshops/xmlworkshops.xml");
    }
}

这是XML:

private static void processStationList(Context mCtx, String fileName)
            throws IOException, XmlPullParserException {
    InputStream is = mCtx.getAssets().open(fileName);
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

    factory.setNamespaceAware(true);

    XmlPullParser xpp = factory.newPullParser();

    xpp.setInput(is, "UTF-8");
    int eventType = xpp.getEventType();

    String tag;

    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_DOCUMENT) {
            // nothing to do here
        } else if (eventType == XmlPullParser.START_TAG) {
            tag = xpp.getName();

            if ("station".equals(tag)) {
                StationDetail detail = processStation(xpp);

                if (null != detail) {
                    ArrayList<StationDetail> list = stationMap.get(detail.areaid);

                    if (null == list) {
                        list = new ArrayList<StationDetail>();
                        stationMap.put(detail.areaid, list);
                    }

                    list.add(detail);
                }
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            // do nothing
        } else if (eventType == XmlPullParser.TEXT) {
            // do nothing
        }

        eventType = xpp.next();
    }

    is.close();
}

我对xmlparser有点不熟悉,并从这个XmlPullParser XML on Android获得了参考。那么有谁知道为什么它不显示数据?感谢

0 个答案:

没有答案