开发者

Android plist xml parsing issue

开发者 https://www.devze.com 2023-04-06 22:54 出处:网络
I have to parse a plist file in Android application. Plist is similar to xml given on following url: http://pastie.org/2583229

I have to parse a plist file in Android application. Plist is similar to xml given on following url:

http://pastie.org/2583229

Will I be able to parse to display data 开发者_开发问答in the app? Which parser is good for this purpose? Please help me here by giving me some suggestions.


Below I have mentioned one way of parsing that XML. I have used XmlPullParser to parse the above mentioned xml:

     String str1 ="<Xml to be parsed>";
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(true);
            XmlPullParser xpp = factory.newPullParser();
            xpp.setInput( new StringReader (str1));
            int eventType = xpp.getEventType();
            while (eventType != XmlPullParser.END_DOCUMENT) {
                String str;
             if(eventType == XmlPullParser.START_DOCUMENT) {
                System.out.println("Start document");
             } else if(eventType == XmlPullParser.START_TAG) {
                 str    =   xpp.getName();
                 System.out.println("Start tag "+str);

             } else if(eventType == XmlPullParser.END_TAG) {
                 System.out.println("End tag "+xpp.getName());
             } else if(eventType == XmlPullParser.TEXT) {
                 System.out.println("Text "+xpp.getText());
             }
             eventType = xpp.next();
            }
           System.out.println("End document");


Your response is xml file so you can read that file using any xml parser

For more details about different types of xml parser follow below link

Different types of xml parsers

0

精彩评论

暂无评论...
验证码 换一张
取 消