I have made a application which reads information from an Api.
Following is my code :
NodeList list = element.getElementsByTagName("detailDescription");
Log.i("ZealDeveloper","I M In detail "+list.getLength());
if(list != null && list.getLength() > 0){
for(int i = 0; i < list.getLength(); i++){
entry = (Element) list.item(i);
description = entry.getAttribute("description");
drivingDirection = entry.getAttribute("drivingDirection");
latitude=entry.getAttribute("latitude");
longitude=entry.getAttribute("longitude");
}
}
NodeList list1 = element.getElementsByTagName("amenity");
Log.i("ZealDeveloper","I M In 2 "+list1.getLength());
if(list1 != null && list1.getLength() > 0){
for(int i = 0; i < list1.getLength(); i++){
entry = (Element) list1.item(i);
nameAmenity = entry.getAttribute("name");
listAmenity.add(nameAmenity);
}
arrAmenity = listAmenity.toArray(new String[listAmenity.size()]);
StringBuilder builder = new StringBuilder();
for ( int i = 0; i < arrAmenity.length; i++ ){
builder.append(arrAmenity[i]+"\n");
}
txtAmenity.setText(builder);
}
#
I am Getting list.getLength() as 0(was getting 1 in pervious versions of android) , so the parser this condition. For amenity tag i m getting the desired list size.
The only reason I can think of is that “detailDescription” is already root of the document so probably
elementis the tag you are seeking for. It doesn’t have any children with the name “detailDescription” sogetElementsByTagName("detailDescription")returns empty list. So change first half of your code as follows: