XML解析节点内的数据

时间:2017-07-26 06:32:54

标签: r xml xml-parsing

我正在尝试解析一些XML。我已经使用xmlTreeParse从网页成功获取了XML,xmlTreeParse被拆分为卡片/会议/竞赛节点。如果我查看第一个会议节点,我该如何提取:

会议名称,

ID,

diffusion_course_name

目前,每当我尝试提取任何内容时,我最终只能选择“种族”孩子。但我想要的只是会议细节?

非常感谢!

> getNodeSet(top,"//cards/meeting[1]")
[[1]]
<meeting name="Bath" id="5" diffusion_course_name="BATH">
  <race id="680058" perform_race_id="" perform_race_id_atr="224436" details_available="1" race_status_code="O">
    <time>2:10</time>
    <date>2017-07-26</date>
    <ampm>pm</ampm>
    <title>British Stallion Studs EBF Novice Stakes (Plus 10 Race)</title>
    <type>F</type>
    <distance>5f10y</distance>
    <group/>
    <tipsAllowed>1</tipsAllowed>
    <predictorAllowed>1</predictorAllowed>
    <bettingLink>1</bettingLink>
    <declaredRunners>5</declaredRunners>
    <liveCommentary>1</liveCommentary>
    <liveTab>1</liveTab>
    <raceDescription>Class 4 Novice</raceDescription>
    <tvText>ATR </tvText>
  </race>
  <race id="680061" perform_race_id="" perform_race_id_atr="224438" details_available="1" race_status_code="O">
    <time>2:40</time>
    <date>2017-07-26</date>
    <ampm>pm</ampm>
    <title>Rainbow Casino Bristol Handicap (Bath Summer Sprint Series Qualifier)</title>
    <type>F</type>
    <distance>5f160y</distance>
    <group>Handicap</group>
    <tipsAllowed>1</tipsAllowed>
    <predictorAllowed>1</predictorAllowed>
    <bettingLink>1</bettingLink>
    <declaredRunners>13</declaredRunners>
    <liveCommentary>1</liveCommentary>
    <liveTab>1</liveTab>
    <raceDescription>Class 5 Handicap</raceDescription>
    <tvText>ATR </tvText>
  </race>
  <race id="680056" perform_race_id="" perform_race_id_atr="224439" details_available="1" race_status_code="O">
    <time>3:10</time>
    <date>2017-07-26</date>
    <ampm>pm</ampm>
    <title>Rainbow Casino Birmingham Handicap</title>
    <type>F</type>
    <distance>5f160y</distance>
    <group>Handicap</group>
    <tipsAllowed>1</tipsAllowed>
    <predictorAllowed>1</predictorAllowed>
    <bettingLink>1</bettingLink>
    <declaredRunners>5</declaredRunners>
    <liveCommentary>1</liveCommentary>
    <liveTab>1</liveTab>
    <raceDescription>Class 4 Handicap</raceDescription>
    <tvText>ATR </tvText>
  </race>
  <race id="680055" perform_race_id="" perform_race_id_atr="224442" details_available="1" race_status_code="O">
    <time>3:40</time>
    <date>2017-07-26</date>
    <ampm>pm</ampm>
    <title>Rainbow Casinos Cardiff Fillies' Handicap</title>
    <type>F</type>
    <distance>1m3f137y</distance>
    <group>Handicap</group>
    <tipsAllowed>1</tipsAllowed>
    <predictorAllowed>1</predictorAllowed>
    <bettingLink>1</bettingLink>
    <declaredRunners>6</declaredRunners>
    <liveCommentary>1</liveCommentary>
    <liveTab>1</liveTab>
    <raceDescription>Class 3 Handicap</raceDescription>
    <tvText>ATR </tvText>
  </race>
  <race id="680059" perform_race_id="" perform_race_id_atr="224443" details_available="1" race_status_code="O">
    <time>4:10</time>
    <date>2017-07-26</date>
    <ampm>pm</ampm>
    <title>Rainbow Casino Aberdeen Handicap (Bath Summer Stayers' Series Qualifier)</title>
    <type>F</type>
    <distance>1m6f</distance>
    <group>Handicap</group>
    <tipsAllowed>1</tipsAllowed>
    <predictorAllowed>1</predictorAllowed>
    <bettingLink>1</bettingLink>
    <declaredRunners>8</declaredRunners>
    <liveCommentary>1</liveCommentary>
    <liveTab>1</liveTab>
    <raceDescription>Class 5 Handicap</raceDescription>
    <tvText>ATR </tvText>
  </race>
  <race id="680060" perform_race_id="" perform_race_id_atr="224447" details_available="1" race_status_code="O">
    <time>4:40</time>
    <date>2017-07-26</date>
    <ampm>pm</ampm>
    <title>Rainbow Bristol Poker Handicap</title>
    <type>F</type>
    <distance>1m2f37y</distance>
    <group>Handicap</group>
    <tipsAllowed>1</tipsAllowed>
    <predictorAllowed>1</predictorAllowed>
    <bettingLink>1</bettingLink>
    <declaredRunners>8</declaredRunners>
    <liveCommentary>1</liveCommentary>
    <liveTab>1</liveTab>
    <raceDescription>Class 5 Handicap</raceDescription>
    <tvText>ATR </tvText>
  </race>
  <race id="680057" perform_race_id="" perform_race_id_atr="224446" details_available="1" race_status_code="O">
    <time>5:10</time>
    <date>2017-07-26</date>
    <ampm>pm</ampm>
    <title>Rainbow Casinos Open 24/7 Handicap</title>
    <type>F</type>
    <distance>1m</distance>
    <group>Handicap</group>
    <tipsAllowed>1</tipsAllowed>
    <predictorAllowed>1</predictorAllowed>
    <bettingLink>1</bettingLink>
    <declaredRunners>8</declaredRunners>
    <liveCommentary>1</liveCommentary>
    <liveTab>1</liveTab>
    <raceDescription>Class 4 Handicap</raceDescription>
    <tvText>ATR </tvText>
  </race>
</meeting> 

attr(,"class")
[1] "XMLNodeSet"

1 个答案:

答案 0 :(得分:0)

您可以尝试xmls2js.It将XML转换为javascript。或者您可以使用nodejs的xml2json模块。 https://www.npmjs.com/package/xml2json