【发布时间】:2014-02-19 20:36:42
【问题描述】:
所以我知道这里已经广泛讨论了这个话题。我在同一件事上发现了很多问题,但仍然无法弄清楚如何解析这个 XML 文件。我正在使用 R,我想从文件中提取经度和纬度。
I'm using this data 和 this guide 但似乎无法使其工作。
这是我的工作:
require(XML)
data <- xmlParse("http://www.donatingplasma.org/index.php?option=com_storelocator&format=feed&searchall=1&Itemid=166&catid=-1&tagid=-1&featstate=0")
xml_data <- xmlToList(data)
一切正常。 XML 文件现在是一个“大列表”。当我尝试提取纬度和经度时,我迷路了。我试过了:
location <- as.list(xml_data[["marker"]][["lat"]])
并得到一个包含 1 行的列表。
我将如何从这个 XML 数据中提取纬度和经度?
数据结构示例:
<markers>
<limited>0</limited>
<marker>
<name>ADMA BioCenters</name>
<category>IQPP Certified</category>
<markertype>
/media/com_storelocator/markers/100713214004000000jl_marker2.png
</markertype>
<featured>false</featured>
<address>
6290 Jimmy Carter Boulevard, Suite 208, Norcross, Georgia 30071
</address>
<lat>33.9290629</lat>
<lng>-84.2204952</lng>
<distance>0</distance>
<fulladdress>
<![CDATA[
<p><img style="margin-left: auto; margin-right: auto;" src="images/jl_marker2.png" alt="jl marker2" width="22" height="22" />IQPP Certified</p>
]]>
</fulladdress>
<phone>678-495-5800</phone>
<url>http://www.atlantaplasma.com</url>
<email/>
<facebook/>
<twitter/>
<tags>
<![CDATA[ ]]>
</tags>
<custom1 name="Custom Field 1">
<![CDATA[ ]]>
</custom1>
<custom2 name="Custom Field 2">
<![CDATA[ ]]>
</custom2>
<custom3 name="Custom Field 3">
<![CDATA[ ]]>
</custom3>
<custom4 name="Custom Field 4">
<![CDATA[ ]]>
</custom4>
<custom5 name="Custom Field 5">
<![CDATA[ ]]>
</custom5>
【问题讨论】:
标签: xml r parsing data-structures