Hi I’ve manage to parse an XML file with some distances in kilometers. But as result I get list of distances of cource, but the last element in the list contains the sum of all the other elements in the list. How can I grab the last element in the list
Some source code:
for(int s=0; s<listOfRoutes.getLength() ; s++){
NodeList listDist = doc.getElementsByTagName("distance");
totalDist = listDist.getLength();
for (int k = 0; k<listDist.getLength(); k++) {
NodeList childs = listDist.item(k).getChildNodes();
for (int l = 0; l < childs.getLength(); l++) {
if (childs.item(l).getNodeName().equals("text")) {
System.out.println(childs.item(l).getTextContent());
//totalKM.add(childs.item(l).getTextContent());
}
}
}
System.out.println("Total Distances: " + totalDist);
}
I’am interested in the last element of the childs NodeList, which contains this information:
0.3 km
0.8 km
0.9 km
0.3 km
0.1 km
0.3 km
40 m
0.3 km
3.0 km
How can I grab this one?
Doesn’t
listDist.item(listDist.getLength() - 1)work?