Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Help me understand this class so that I can modify it?

Avatar of CyanBlue
CyanBlueFlag for United States of America asked on
4 Comments1 Solution492 ViewsLast Modified:
Hi...  :)

I am following this blog post and try to update the class to get different data from the XML file...

This is the actual call to the Geocoder class from the ReverseGeocodeLookupTask class...
localityName = Geocoder.reverseGeocode(currentLocation);
The Geocoder class then calls Google Maps API to get the XML back...
InputStreamReader isr =  new InputStreamReader(connection.getInputStream());
InputSource source = new InputSource(isr);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader xr = parser.getXMLReader();
GoogleReverseGeocodeXmlHandler handler = new GoogleReverseGeocodeXmlHandler();


localityName = handler.getLocalityName();
I see that it is calling GoogleReverseGeocodeXmlHandler class, which is shown below, but I don't really understand how this class works...
public class GoogleReverseGeocodeXmlHandler extends DefaultHandler
    private boolean inLocalityName = false;
    private boolean finished = false;
    private StringBuilder builder;
    private String localityName;
    public String getLocalityName()
        return this.localityName;
    public void characters(char[] ch, int start, int length)
           throws SAXException {
        super.characters(ch, start, length);
        if (this.inLocalityName && !this.finished)
            if ((ch[start] != '\n') && (ch[start] != ' '))
                builder.append(ch, start, length);

    public void endElement(String uri, String localName, String name)
            throws SAXException
        super.endElement(uri, localName, name);
        if (!this.finished)
            if (localName.equalsIgnoreCase("LocalityName"))
                this.localityName = builder.toString();
                this.finished = true;
            if (builder != null)

    public void startDocument() throws SAXException
        builder = new StringBuilder();

    public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException
        super.startElement(uri, localName, name, attributes);
        if (localName.equalsIgnoreCase("LocalityName"))
            this.inLocalityName = true;
The XML output looks like this...
<?xml version="1.0"?>
<AddressDetails xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" Accuracy="8">
				<SubAdministrativeAreaName>Santa Clara</SubAdministrativeAreaName>
					<LocalityName>Mountain View</LocalityName>
						<ThoroughfareName>1600 Amphitheatre Pkwy</ThoroughfareName>
What I'd like to do is to get both localityName and countryNameCode at the same time...  
What I am not able to find is 'what' variable contains the whole XML string and how this GoogleReverseGeocodeXmlHandler class works since I don't see anything like a constructor and whatnot...

Thank you very much...  :)

Avatar of CEHJ
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers