title: Parsing XML using XPath in Java using Google Geocode
body: <pre><code>kohaNimi = "Tallinn";
  URL myUrl = new URL("http://maps.googleapis.com/maps/api/geocode/xml?address=" + kohaNimi + "&amp;sensor=false");
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();
  Document doc = builder.parse(myUrl.openStream());
  XPathFactory xPathfactory = XPathFactory.newInstance();
  XPath xpath = xPathfactory.newXPath();
  XPathExpression expr = xpath.compile("/GeocodeResponse/result/bounds/southwest/lat");
  String swLat = expr.evaluate(doc, XPathConstants.STRING).toString();
  System.out.println("swLat: " + swLat );
  </code></pre>
  
  <p>So I am trying to use Google geocode API to get the coordinates of a town, but I have trouble parsing the xml. I am trying to use xPath with Java. I can verify that ... does exist. The problem is that when I try to parse this xml I wont get any text as response. I have looked over the code and can't seem to figure out what is wrong. I used this blogpost to assemble my code: <a href="http://tunatore.wordpress.com/2011/05/20/how-to-use-xpath-i-java-simple-example/" rel="nofollow">http://tunatore.wordpress.com/2011/05/20/how-to-use-xpath-i-java-simple-example/</a></p>
  
  <p>You can verify that xpath is correct(should get response) from here: <a href="http://maps.googleapis.com/maps/api/geocode/xml?address=Tallinn&amp;sensor=false" rel="nofollow">http://maps.googleapis.com/maps/api/geocode/xml?address=Tallinn&amp;sensor=false</a></p>
  
  <p>Can anyone spot what is wrong?</p>