Created
October 15, 2009 01:47
-
-
Save dcbriccetti/210570 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml._ | |
XML.loadString("""<?xml version="1.0" encoding="UTF-8" ?> | |
<kml xmlns="http://earth.google.com/kml/2.0"><Response> | |
<name>32.867930,-117.131160</name> | |
<Status> | |
<code>200</code> | |
<request>geocode</request> | |
</Status> | |
<Placemark id="p1"> | |
<address>Miramar, CA, USA</address> | |
<AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>San Diego</SubAdministrativeAreaName><Locality><LocalityName>Miramar</LocalityName></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails> | |
<ExtendedData> | |
<LatLonBox north="32.9311267" south="32.8561736" east="-117.0543364" west="-117.1823958" /> | |
</ExtendedData> | |
<Point><coordinates>-117.1183661,32.8936581,0</coordinates></Point> | |
</Placemark> | |
<Placemark id="p2"> | |
<address>San Diego, CA 92126, USA</address> | |
<AddressDetails Accuracy="5" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>San Diego</SubAdministrativeAreaName><Locality><LocalityName>San Diego</LocalityName><PostalCode><PostalCodeNumber>92126</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails> | |
<ExtendedData> | |
<LatLonBox north="32.9419330" south="32.8509410" east="-117.1129030" west="-117.2143980" /> | |
</ExtendedData> | |
<Point><coordinates>-117.1382404,32.8976097,0</coordinates></Point> | |
</Placemark> | |
</Response></kml> | |
""") \ "Response" \ "Placemark" \ "address" toList match { | |
case a :: _ => a.text | |
case _ => "Not found" | |
} | |
// Jorge Ortiz offers this bit of elegance: | |
(... \ "Response" \ "Placemark" \ "address"). | |
firstOption.map(_.text).getOrElse(latLong) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment