0

I am trying to parse the xml file from a web address in android. But it displays none

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");
    }
}

this is the 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();
}

I'm a bit unfamiliar with xmlparser and got the reference from this XmlPullParser XML on Android. So does anyone know why it does not display the data? Thanks

4
  • So, after execution of processStationList(), stationMap and list sizes are 0? Commented Jun 26, 2013 at 10:09
  • yes they are. They returned nothing Commented Jun 26, 2013 at 10:41
  • hmm, seems here staging.hpgue.com:8270/newiklaim/workshops/xmlworkshops.xml no 'station' tags. Commented Jun 26, 2013 at 12:15
  • I'm not sure but it worked for me. Try using tag = xpp.getName().toString() and then u do String comparison. Commented Jul 5, 2013 at 19:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.