2017-07-26 103 views
1

我想解析一些XML。我已經成功地使用xmlTreeParse從網頁中獲取XML,該XML文件被分成卡片/會議/比賽節點。如果我看的第一次會議上的節點,我如何提取:XML解析節點內的數據

會議名稱,

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" 

回答

0

您可以嘗試xmls2js.It將XML轉換爲javascript。或者你可以使用nodejs的xml2json模塊。 https://www.npmjs.com/package/xml2json

+0

是用於R? – Tammboy

+0

對不起,我應該在我的問題中明確指出,我在R中執行了這一切,主要使用R-XML軟件包。謝謝。 – Tammboy

+0

抱歉,我錯了 – Shrinath