"> xmlroot
"<Period>
<timeInterval>
<start>2015-10-20T00:00Z</start>
<end>2015-10-21T00:00Z</end>
</timeInterval>
<resolution>PT60M</resolution>
<Point>
<position>1</position>
<price.amount>24.20</price.amount>
</Point>
<Point>
<position>2</position>
<price.amount>24.28</price.amount>
</Point>
<Point>
<position>3</position>
<price.amount>24.89</price.amount>
</Point>
<Point>
<position>4</position>
<price.amount>25.64</price.amount>
</Point>
<Point>
<position>5</position>
<price.amount>26.36</price.amount>
</Point>
<Point>
<position>6</position>
<price.amount>27.83</price.amount>
</Point>
<Point>
<position>7</position>
<price.amount>28.88</price.amount>
</Point>
<Point>
<position>8</position>
<price.amount>29.96</price.amount>
</Point>
<Point>
<position>9</position>
<price.amount>28.73</price.amount>
</Point>
<Point>
<position>10</position>
<price.amount>28.09</price.amount>
</Point>
<Point>
<position>11</position>
<price.amount>27.54</price.amount>
</Point>
<Point>
<position>12</position>
<price.amount>27.52</price.amount>
</Point>
<Point>
<position>13</position>
<price.amount>27.35</price.amount>
</Point>
<Point>
<position>14</position>
<price.amount>27.18</price.amount>
</Point>
<Point>
<position>15</position>
<price.amount>27.04</price.amount>
</Point>
<Point>
<position>16</position>
<price.amount>27.39</price.amount>
</Point>
<Point>
<position>17</position>
<price.amount>27.17</price.amount>
</Point>
<Point>
<position>18</position>
<price.amount>27.23</price.amount>
</Point>
<Point>
<position>19</position>
<price.amount>27.16</price.amount>
</Point>
<Point>
<position>20</position>
<price.amount>25.77</price.amount>
</Point>
<Point>
<position>21</position>
<price.amount>24.80</price.amount>
</Point>
<Point>
<position>22</position>
<price.amount>24.08</price.amount>
</Point>
<Point>
<position>23</position>
<price.amount>23.77</price.amount>
</Point>
<Point>
<position>24</position>
<price.amount>23.64</price.amount>
</Point>
</Period> "
我在R:getNodeSet(doc = xmlroot,path = 'Period/Point')
得到这个结果:
list()
attr(,"class")
[1] "XMLNodeSet"
我希望能够将这些数据提取到一个简单的数据框架中 - 任何想法?
供参考:
类(xmlroot) [1]&#34; XMLInternalElementNode&#34; &#34; XMLInternalNode&#34; &#34; XMLAbstractNode&#34;
答案 0 :(得分:2)
使用XPath时,可以指定节点而不使用整个路径,如下所示:“// Point”。查看this关于在R中操作XML文件的精彩教程。
对于您的具体示例,您可以使用:
xmlToDataFrame(getNodeSet(xmlRoot, "//Point"))
返回
position price.amount
1 1 24.20
2 2 24.28
3 3 24.89
4 4 25.64
5 5 26.36
6 6 27.83
......等等。