0
我在這個XML的文件格式:選擇基於屬性的特定屬性值
<league country="argentina" name="Argentina: Torneo Federal A - Winners Stage" cup="False" id="2909" sub_id="29094">
<match alternate_id="4187269" alternate_id_2="4394549" date="14.08.2015" id="4304775" static_id="14081523515562337775" status="FT" time="18:00">
<home goals="2" id="2351556" name="Club Atletico Mitre"></home>
<away goals="1" id="2337775" name="Chaco For Ever"></away>
<events>
<event assist="" assistid="" id="22958994" minute="32" player="Juan Pablo Villafane" playerid="" result="[1 - 0]" team="home" type="goal"></event>
<event assist="" assistid="" id="22958995" minute="48" player="Aldo Visconti" playerid="" result="[1 - 1]" team="away" type="goal"></event>
<event assist="" assistid="" id="22958996" minute="90" player="Emanuel Lazzarini" playerid="" result="[2 - 1]" team="home" type="goal"></event>
</events>
<ht score="[1-0]"></ht>
<ft score="[2-1]"></ft>
</match></league><league country="argentina" name="Argentina: Torneo Federal A - Losers Stage" cup="False" id="2909" sub_id="29095"><match alternate_id="4178253" alternate_id_2="4410516" date="14.08.2015" id="4295774" static_id="14081523557572337894" status="FT" time="18:00">
<home goals="2" id="2355757" name="Velez de San Ramon"></home>
<away goals="1" id="2337894" name="Sportivo Patria"></away>
<events>
<event assist="" assistid="" id="23118664" minute="11" player="Diego Suarez" playerid="" result="[1 - 0]" team="home" type="goal"></event>
<event assist="" assistid="" id="23118665" minute="64" player="Luis Leguizamon" playerid="" result="[2 - 0]" team="home" type="goal"></event>
<event assist="" assistid="" id="23118666" minute="67" player="Rodrigo Ramirez (o.g.)" playerid="" result="[2 - 1]" team="away" type="goal"></event>
</events>
<ht score="[1-0]"></ht>
<ft score="[2-1]"></ft>
這是我的控制器:
xml = Nokogiri::XML(f)
path = "//match[@static_id='user.matchid']"
@country = xml.xpath(path)
我怎樣才能得到團隊的名稱,依據條件是屬性值"result" = [1-0]
或[0-1]
?
歡迎堆棧溢出。當您提供數據或代碼時,將其降至必要的最低水平,以顯示您遇到的問題。換句話說,你的XML非常冗長,需要減少。這也是無效的。當Nokogiri _can_修復它時,這樣做會導致XML通常無法準確反映原始內容。未能提供準確的反映真實信息的輸入數據會減慢或停止我們幫助您的能力,因此請幫助我們爲您提供幫助並提供準確,最簡單的數據。 –