Link to home
Start Free TrialLog in
Avatar of Waschtel
Waschtel

asked on

How to parse a kml/xml file in Java

Hi,

I'm trying to geocode an address with google maps.

You can look at the kml file I am trying to parse by typing:

http://maps.google.com/maps/geo?q=Hofbrunnstrasse+39,Munich,Germany&output=xml&key=abcdefg

into your browser.


I try to create a DOM document from the kml file returned by the google maps server in Java, but I am  encountering problems when there are german "Umlaute (special characters like 'ä,'ö','ü')" in the kml response. Is there any way to parse the kml file differently, so I don't get an exception thrown?

Thanks for any help!

Sebastian.
String question = "http://maps.google.com/maps/geo?q=Hofbrunnstrasse+39,Munich,Germany&output=xml&key=abcdefg"
try {
            builder = builderFactory.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        }
        try {
// Following line throws an exception of type:
//com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.
 
            Document document = builder.parse(question);
        } catch (SAXException e) {
            e.printStackTrace();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Waschtel
Waschtel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial