Android Open Source - simple-restaurant Restaurant X M L Fetcher






From Project

Back to project page simple-restaurant.

License

The source code is released under:

GNU General Public License

If you think the Android project simple-restaurant listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package pad.practica1.restaurante.restaurant;
/*  w ww .  j  a  v a  2s.  com*/
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import pad.practica1.restaurante.R;
import pad.practica1.restaurante.R.xml;
import android.content.Context;
import android.util.Log;

public class RestaurantXMLFetcher implements RestaurantFetcher {
  @Override
  public ArrayList<Restaurant> getRestaurants(Context context) {
    ArrayList<Restaurant> restaurants = new ArrayList<Restaurant>();
    XmlPullParser parser = context.getResources().getXml(R.xml.restaurants_db);
    try {
      while (parser.next() != XmlPullParser.END_DOCUMENT) {
        String name = parser.getName();
        if ((name != null) && name.equals("restaurant") && parser.getEventType() != XmlPullParser.END_TAG) {
          int size = parser.getAttributeCount();
          Restaurant restaurant = new Restaurant(context);
          for (int i = 0; i < size; i++) {
            String attrName = parser.getAttributeName(i);
            String attrValue = parser.getAttributeValue(i);
            
            restaurant.setAttribute(attrName, attrValue);
          }
                    
          restaurants.add(restaurant);
        }
      }
    } catch (Exception e) {
      Log.e("ReadXMLResourceFile", e.getMessage(), e);
    }

    return restaurants;
  }
}




Java Source Code List

pad.practica1.restaurante.MainActivity.java
pad.practica1.restaurante.RestaurantApplication.java
pad.practica1.restaurante.RestaurantDetailActivity.java
pad.practica1.restaurante.ResultsActivity.java
pad.practica1.restaurante.database.DBHelper.java
pad.practica1.restaurante.restaurant.RestaurantFetcher.java
pad.practica1.restaurante.restaurant.RestaurantSQLiteFetcher.java
pad.practica1.restaurante.restaurant.RestaurantXMLFetcher.java
pad.practica1.restaurante.restaurant.Restaurant.java