解析到一个查询XML响应 [英] Parsing an XML response to a query
本文介绍了解析到一个查询XML响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图提取县FIPS数量进行了大量的经度和纬度线。我可以从FCC API的数据,但我有一个很难读取到R上。
I am trying to extract the County fips number for a large number of lines of longitude and latitude. I can get the data from an FCC API, but am having a hard time reading it into R.
例如,当我运行下面的code在R:
For example, when I run the following code in R:
library(httr)
fips <- GET("http://data.fcc.gov/api/block/find", query = list(latitude = 48.9905, longitude = -122.2733, showall="false"))
result <- content(fips, as = "parsed")
result
对象结果显示如下
the object "result" is displayed as follows
{xml_document}
<Response>
[1] <Block FIPS="530730102002091"/>
[2] <County FIPS="53073" name="Whatcom"/>
[3] <State FIPS="53" code="WA" name="Washington"/>
我感兴趣的信息是县FIPS code53073.我应该如何去提取只是多少?
The information I am interested in is the county FIPS code "53073." How should I go about extracting just that number?
推荐答案
您必须解析 XML
从API返回
You have to parse the XML
returned from that API
library("httr")
library("XML")
fips <- GET("http://data.fcc.gov/api/block/find", query = list(latitude = 48.9905, longitude = -122.2733, showall="false"))
result <- content(fips, as = "parsed")
> xmlToList(xmlParse(result))$County["FIPS"]
FIPS
"53073"
这篇关于解析到一个查询XML响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文