2

I'm using XmlPullParser sample but when run in API 8 or 10 the values return null (I'm not sure), but in other version API 16 + working fine. What could be happening?. The parameter that returns null is getAttributeValue(null, "name").

UPDATE: Into the AndroidManifest use android:minSdkVersion="8"

public class SitesXmlPullParser {

    static final String KEY_SITE = "site";

    public static List<StackSite> getStackSitesFromFile(Context ctx) {
        List<StackSite> stackSites;
        stackSites = new ArrayList<StackSite>();

        StackSite curStackSite = null;


        try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            XmlPullParser xpp = factory.newPullParser();

            FileInputStream fis = ctx.openFileInput("StackSites.xml");
            BufferedReader reader = new BufferedReader(new InputStreamReader(fis));

            xpp.setInput(reader);

            int eventType = xpp.getEventType();

            while (eventType != XmlPullParser.END_DOCUMENT) {
                String tagname = xpp.getName();

                switch (eventType) {
                case XmlPullParser.START_TAG:
                    if (tagname.equalsIgnoreCase(KEY_SITE)) {
                        curStackSite = new StackSite();
                    }
                    break;

                case XmlPullParser.END_TAG:
                    if (tagname.equalsIgnoreCase(KEY_SITE)) {
                        // This values return null
                        String name = xpp.getAttributeValue(null, "name");
                        String link = xpp.getAttributeValue(null, "link");
                        String about = xpp.getAttributeValue(null, "about");
                        String image = xpp.getAttributeValue(null, "image");
                        curStackSite.setName(name);
                        curStackSite.setLink(link);
                        curStackSite.setAbout(about);
                        curStackSite.setImgUrl(image);                      
                        stackSites.add(curStackSite);
                    }
                    break;

                default:
                    break;
                }
                eventType = xpp.next();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return stackSites;
    }
}
4

0 回答 0