Thursday, 19 February 2015

Get attribute of inner node in XML



I have a next XML file



<country name="Абхазия">
<city id="37188" region="27028" head="" type="3" country="Абхазия" part="" resort="" climate="">Новый Афон</city>
</country>


And i need to get the id attribute from the inner city node. I've done the next code, but i have no idea how to proceed:



Document doc = parser.getDomElement(xml);
NodeList nl = doc.getElementsByTagName(KEY_COUNTRY);

for (int i = 0; i < nl.getLength(); i++) {

Element e = (Element) nl.item(i);
String city = parser.getValue(e, KEY_CITY);

}

No comments:

Post a Comment