这是xml
public class TrackingService extends Service implements AsyncTaskCallback,
LocationListener {
LocationManager lm;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
detectLocation();
return START_STICKY;
}
private void detectLocation() {
// TODO Auto-generated method stub
Toast.makeText(this, "Inside detectlocation()", Toast.LENGTH_SHORT)
.show();
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30 * 1000, 0,
this);
enableGPS(lm);
}
@Override
public void onDestroy() {
super.onDestroy();
lm.removeUpdates(this);
System.out.println("ABC locationManager is not equal null.");
}
public void stopTrackingService(){
lm.removeUpdates(this);
}
}
我需要阅读此xml文件并创建一个包含
的列表public class Map extends FragmentActivity implements OnMapReadyCallback, ConnectionCallbacks, OnConnectionFailedListener{
@Override
protected void onDestroy() {
super.onDestroy();
// To stop the service when the user closed the app in the background and the map ativity was opened.
stopAlarm();
Intent i = new Intent(this, TrackingService.class);
stopService(i);
System.out.println("ABC Map onDestroy() was invoked!");
}
}
简单快捷的方法是什么?
答案 0 :(得分:4)
您可以使用LinqToXml
var list = XDocument.Load(filename)
.Descendants("Result")
.Select(x => (string)x)
.ToList();
答案 1 :(得分:1)
使用XML阅读器和编解码器将DOM树转换为列表。