DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new ByteArrayInputStream(xml.getBytes()));
// normalize text representation
doc.getDocumentElement ().normalize ();
NodeList listOfResults = doc.getElementsByTagName("Result");
for(int i= 0; i< listOfResults.getLength(); i++){
ResultGeoCodeApi result = new ResultGeoCodeApi();
Node nodeResult = listOfResults.item(i);
if(nodeResult.getNodeType() == Node.ELEMENT_NODE){
Element elementResult = (Element)nodeResult;
result.setPrecision(elementResult.getAttribute("precision"));
NodeList latitudes = elementResult.getElementsByTagName("Latitude");
Element latitudeElement = (Element)latitudes.item(0);
NodeList latitudeNodes = latitudeElement.getChildNodes();
result.setLatitude(((Node)latitudeNodes.item(0)).getNodeValue().trim());
NodeList longitudes = elementResult.getElementsByTagName("Longitude");
Element longitudeElement = (Element)longitudes.item(0);
NodeList longitudeNodes = longitudeElement.getChildNodes();
result.setLongitude(((Node)longitudeNodes.item(0)).getNodeValue().trim());
NodeList addresses = elementResult.getElementsByTagName("Address");
Element addressElement = (Element)addresses.item(0);
NodeList addressNodes = addressElement.getChildNodes();
result.setAddress(((Node)addressNodes.item(0)).getNodeValue().trim());
NodeList cities = elementResult.getElementsByTagName("City");
Element cityElement = (Element)cities.item(0);
NodeList cityNodes = cityElement.getChildNodes();
result.setCity(((Node)cityNodes.item(0)).getNodeValue().trim());
NodeList states = elementResult.getElementsByTagName("State");
Element stateElement = (Element)states.item(0);
NodeList stateNodes = stateElement.getChildNodes();
result.setState(((Node)stateNodes.item(0)).getNodeValue().trim());
NodeList zips = elementResult.getElementsByTagName("Zip");
Element zipElement = (Element)zips.item(0);
NodeList zipNodes = zipElement.getChildNodes();
result.setZip(((Node)zipNodes.item(0)).getNodeValue().trim());
NodeList countries = elementResult.getElementsByTagName("Country");
Element countryElement = (Element)countries.item(0);
NodeList countryNodes = countryElement.getChildNodes();
result.setCountry(((Node)countryNodes.item(0)).getNodeValue().trim());
results.add(result);
}
}