I need some help understanding how to read the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetRouteSummaryForStopResponse xmlns="http://octranspo.com">
<GetRouteSummaryForStopResult>
<StopNo xmlns="http://tempuri.org/">5212</StopNo>
<StopDescription xmlns="http://tempuri.org/">BANNER / PARKMOUNT</StopDescription>
<Error xmlns="http://tempuri.org/" />
<Routes xmlns="http://tempuri.org/">
<Route>
<RouteNo>82</RouteNo>
<DirectionID>1</DirectionID>
<Direction>Westbound</Direction>
<RouteHeading>Bayshore</RouteHeading>
</Route>
<Route>
<RouteNo>282</RouteNo>
<DirectionID>0</DirectionID>
<Direction>Inbound</Direction>
<RouteHeading>Mackenzie King</RouteHeading>
</Route>
</Routes>
</GetRouteSummaryForStopResult>
</GetRouteSummaryForStopResponse>
</soap:Body>
</soap:Envelope>
Im trying to retrieve the text of <StopNo> and <StopDescription> and others after. To debug I
m trying to print getName() and getText().
//XmlPullParser - START
try {
XmlPullParser parser = Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(in, null);
while (parser.next() != XmlPullParser.END_DOCUMENT) {
Log.i("**********", parser.getName() + " " + parser.getText());
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
//Get Tag name
String name = parser.getName();
// Starts by looking for the temperature
if (name.equalsIgnoreCase("StopNo")) {
stopNumber = parser.getText();
Log.i("***** OS doInBackground", "stopNumber " + stopNumber);
}
//look for speed tag
if (name.equals("StopDescription")) {
stopDescription = parser.getText();
Log.i("***** OS doInBackground", "stopDescription " + stopDescription);
}
}
} catch (Exception e){
Log.i("****** Exception XML", e.getMessage());
}
if (in!=null) {
try {
in.close();
} catch (IOException e) {
}
}
However, I`m getting the following output. First it prints getName() opening tag, getText() = null, then null for tag and getText() = text and so on.
...
I/**********: StopNo null
I/***** OS doInBackground: stopNumber null
I/**********: null 5212
I/**********: StopNo null
I/**********: StopDescription null
I/***** OS doInBackground: stopDescription null
I/**********: null BANNER / PARKMOUNT
I/**********: StopDescription null
I/**********: Error null
I/**********: Error null
I/**********: Routes null
I/**********: Route null
I/**********: RouteNo null
I/**********: null 82
I/**********: RouteNo null
...
I cannot understand why the getName() and getText() are off?