I have this xml structure:
<markers>
<marker provincia="Guayas" lat="-2.33" lng="-77.63" />
<marker provincia="Pichincha" lat="-3.23" lng="-81.13" />
</markers>
and I want to show it in a listview. I have based in this example but this have other xml structure. I think I need to put the parameter getAttributeCount(), I found this sample but I don´t understand very well. Can you guide me?. This is the code modify:
package com.makemyandroidapp.example.stacksites;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import android.content.Context;
public class SitesXmlPullParser {
static String KEY_MARKER = "marker";
public static List<StackSite> getStackSitesFromFile(Context ctx) {
List<StackSite> stackSites;
stackSites = new ArrayList<StackSite>();
try {
// Get our factory and PullParser
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
// Open up InputStream and Reader of our file.
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:
break;
case XmlPullParser.END_TAG:
if (tagname.equals(KEY_MARKER)) {
KEY_MARKER = xpp.getAttributeValue(null, "provincia");
KEY_MARKER = xpp.getAttributeValue(null, "lat");
KEY_MARKER = xpp.getAttributeValue(null, "lng");
}
else{
}
break;
default:
break;
}
//move on to next iteration
eventType = xpp.next();
}
} catch (Exception e) {
e.printStackTrace();
}
// return the populated list.
return stackSites;
}
}