I have XML file that I downloaded from a web service, the issue that I have is that I cannot get it display the data correctly outside of the loop.
The XML format is set up like:
<section>
<outage>
<dummydata>test</dummydata>
</outage>
<outage>
<dummydata>test2</dummydata>
</outage>
</section>
<section>
<outage>
<dummydata>test3</dummydata>
<outage>
</section>
Note some sections can have more that one outage. As you can see below the counts are right but the one outage is from the 4.
01-24 22:54:49.176: I/System.out(1924): Outage Count per sect 1
01-24 22:54:49.176: I/System.out(1924): Outage Count per sect 1
01-24 22:54:49.176: I/System.out(1924): Outage Count per sect 1
01-24 22:54:49.176: I/System.out(1924): Outage Count per sect 1
01-24 22:54:49.176: I/System.out(1924): Outage Count per sect 4
01-24 22:54:49.186: I/System.out(1924): Outage Count per sect 1
01-24 22:54:49.186: I/System.out(1924): Outage Count per sect 1
01-24 22:54:49.196: I/System.out(1924): Outages : 763674
and this is the code that is doing all the work
for (int j = 0; j < arrPolygons.size(); j++) {
if (isPointInPolygon(point, arrPolygons.get(j).getPoints())) {
for (int outageInfo = 0; outageInfo < nodeList.getLength(); outageInfo++) {
outageData = new LinkedList<HashMap<String, String>>();
Node ouageInfoNode = nodeList.item(outageInfo);
Element ouageInfoElement = (Element) ouageInfoNode;
NodeList ouageInfoList = ouageInfoElement.getElementsByTagName("Outage");
System.out.println("Outage Count per sect "+ouageInfoList.getLength());
for (int outages = 0; outages < ouageInfoList.getLength(); outages++) {
Node outageNode = ouageInfoList.item(outages);
Element outageDataElement = (Element) outageNode;
NodeList outageDataList =outageDataElement.getElementsByTagName("outagenum");
outageDataElement = (Element) outageDataList.item(0);
outageDataList = outageDataElement.getChildNodes();
outagenum = ((Node) outageDataList.item(0))
.getNodeValue();
//This is what I want to loop
HashMap<String, String> map = new HashMap<String, String>();
map.put("outagenum", outagenum);
outageData.add(outages, map);
}
}
Toast.makeText(MainActivity.this, "Inside " + arrPolygons.get(j).getId()+" "+ outageData.get(j), Toast.LENGTH_LONG).show();
System.out.println("Outages : " + outageData.get(0));
}
}
}
}
my outcome should look like
Index 0 - {test,test2}
Index 1 - {test3}
Can anybody tell me what I am doing wrong within this loop?
should