Database Reference
In-Depth Information
Shaking the XML Tree
Parsing well-formed and valid XML should be less convoluted than parsing the sheriff's
HTML. An XML parsing package is available for R; here's how to install it from CRAN's
repository:
> install.packages("XML")
> library("XML")
WARNING
If you are behind a firewall or proxy and getting errors:
On Unix, set your http_proxyenvironment variable.
On Windows, try the custom install R wizard with the “internet2” option instead of “standard”.
You can find additional information at
http://cran.r-project.org/bin/windows/base/rw-FAQ.html#The-
Our goal is to extract values contained within the
<Latitude>
and
<Longitude>
leaf nodes.
These nodes live within the
<Result>
node, which lives inside a
<ResultSet>
node, which
itself lies inside the root node.
To find an appropriate library for getting these values, call
library(help=XML)
. This func-
tion lists the functions in the XML package.
> library(help=XML)
#hit space to scroll, q to exit
> ?xmlTreeParse
You'll see that the function
xmlTreeParse
will accept an XML file or URL and return an R
structure. After inserting your Yahoo App ID, paste in this block:
> library(XML)
> appid<-'
<put your appid here>
'
> street<-"1 South Broad Street"
> requestUrl<-paste(
"http://local.yahooapis.com/MapsService/V1/geocode?appid=",
appid,
"&street=",
URLencode(street),
"&city=Philadelphia&state=PA"
,sep="")
> xmlResult<-xmlTreeParse(requestUrl,isURL=TRUE)