read setting name list from resource with XmlPullParser : XmlPullParser « Development « Android

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » Development » XmlPullParser 
read setting name list from resource with XmlPullParser
  
import java.io.IOException;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.content.res.XmlResourceParser;
import android.util.Log;

class Main {
    private static final String TAG = "Utility";

    public static final String ATTR_NAME = "name";

    public static final String TAG_NAME = "settings";
  /**
   * read setting name list from resource
   
   @return list of setting name
   */
  public static ArrayList<String> getSettingNameList(int resource,
      Context context) {
    XmlResourceParser parser = context.getResources().getXml(resource);
    ArrayList<String> settingNameList = new ArrayList<String>();

    try {
      while (parser.next() != XmlPullParser.END_DOCUMENT) {
        if (parser.getEventType() == XmlPullParser.START_TAG
            && TAG_NAME.equals(parser.getName())) {
          String settingName = parser.getAttributeValue(null,
              ATTR_NAME);
          if (settingName != null) {
            Log.i(TAG, settingName);
            settingNameList.add(settingName);
          }
        }
      }
    catch (XmlPullParserException e) {
      Log.e(TAG, "Parser Exception : ", e);
    catch (IOException e) {
      Log.e(TAG, "IOException : ", e);
    }

    parser.close();

    return settingNameList;
  }

}

   
    
  
Related examples in the same category
1.Move To Next Sibling XmlPullParser
2.XmlPullParser Util
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.