1
我正在開發一個Android 2.2應用程序。用Android解析XML
我有RES/XML下面的XML文件:
<?xml version="1.0" encoding="iso-8859-1"?>
<data>
<turo>
<name>Rodo</name>
<latitude>37.212123</latitude>
<longitude>0.1231231</longitude>
</turo>
</data>
我越來越瘋狂,因爲我無法找到一個例子,看我怎麼能解析該文件。
我也有下面的類來存儲檢索的數據:
public class Turo{
private String name;
private Location location;
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public Turo(String name){
setName(name);
}
public void setLocation(Location location) {
this.location = location;
}
public Location getLocation() {
return location;
}
}
這是我的方法來解析它(它未完):
public Vector<Turo> getTurosFromXML(Activity activity, int xmlId) throws XmlPullParserException, IOException {
StringBuffer stringBuffer = new StringBuffer();
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(xmlId);
xpp.next();
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT)
{
...
}
}
你能幫助我嗎?