I am new to R and I want to use R to get some data from the website.
I tried to get some cities index and cities name from Yahoo API, and thus I need to parse an XML file.
but when I tried to get the value of some nodes using getNodeSet()
function, R returns an empty list.
Could our experts give me some advice about this kind of issue?
thanks a lot!
yahoo link: Yahoo weather API
and I've updated the XML file.
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="346" yahoo:created="2015-07-30T02:48:20Z" yahoo:lang="zh-CN">
<diagnostics>
<publiclyCallable>true</publiclyCallable>
<url execution-start-time="24" execution-stop-time="114" execution-time="90">
<![CDATA[
http://wws.geotech.yahooapis.com/v1/counties/CN;start=0;count=1000
]]>
</url>
<user-time>121</user-time>
<service-time>90</service-time>
<build-version>0.2.154</build-version>
</diagnostics>
<results>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198131">
<woeid>26198131</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Wuwei</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198056">
<woeid>26198056</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Jinchang</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198129">
<woeid>26198129</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Lanzhou</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198130">
<woeid>26198130</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Baiyin</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198128">
<woeid>26198128</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Linxia Huizu</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198133">
<woeid>26198133</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Zhangye</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198127">
<woeid>26198127</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Dingxi</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198125">
<woeid>26198125</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Gannan Zangzu</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198042">
<woeid>26198042</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Ili Kazakh</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198043">
<woeid>26198043</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Kizilsu Kirghiz</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198047">
<woeid>26198047</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Aletai</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198049">
<woeid>26198049</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Hetian</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198262">
<woeid>26198262</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Jiamusi</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198263">
<woeid>26198263</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Shuangyashan</name>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng" xml:lang="en-US" yahoo:uri="http://where.yahooapis.com/v1/place/26198057">
<woeid>26198057</woeid>
<placeTypeName code="9">Prefecture</placeTypeName>
<name>Daxing'anling</name>
</place>
</results>
</query>
<!-- total: 121 -->
<!-- pprd1-node1004-lh1.manhattan.ne1.yahoo.com -->
I tried by this code :
> library(XML)
> temp = xmlTreeParse("yql.xml",useInternalNodes = TRUE)
> woeid = getNodeSet(temp,"//woeid")
> woeid
But its return is :
> list()
attr(,"class")
[1] "XMLNodeSet"