I'm using a XML parser in many activity and now I have a problem :
Here is my XML FILE
And I don't want all of the childs from the "stop" parent.
Because there are the same child in "stop" and in "departures" and I only want the data from "departures" child.
How can I do this with my code ?
public void parseXML()
{
try {
URI url=null;
url = new URI(Departs.passedCode);
try {
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(new HttpGet(url));
stream = response.getEntity().getContent();
} catch (IOException e) {
e.printStackTrace();
publishProgress("Exception: " + e.toString());
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringComments(true);
dbf.setIgnoringElementContentWhitespace(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(stream);
doc.getDocumentElement().normalize();
NodeList stopList = doc.getElementsByTagName("lineCode");
String Name="";
for (int i = 0; i < stopList.getLength(); i++)
{
Element elementStopCode = (Element)stopList.item(i);
String strName = elementStopCode.getTextContent();
Name = Name.concat("\n"+ strName);
}
publishProgress(Name);
}
catch (Exception e)
{
e.printStackTrace();
publishProgress("Exception: " + e.toString());
}
}
Thank you for your help
No comments:
Post a Comment