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)
{
...
}
}
你能帮助我吗?