0

因为我无法注册

http://www.spotify.com/ns/music/1

命名空间我正在使用以下

/*[name()='tracks']/*[name()='track']/*[name()='name']

用于检索曲目名称的字符串。问题是我只想要第一个轨道名称,是否有任何解决方法可以只选择第一个轨道块?

<tracks xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.spotify.com/ns/music/1">
<opensearch:Query role="request" startPage="1" searchTerms="hypo disco"/>
<opensearch:totalResults>2</opensearch:totalResults>
<opensearch:startIndex>0</opensearch:startIndex>
<opensearch:itemsPerPage>100</opensearch:itemsPerPage>
<track href="spotify:track:5uYWzsjWBui67Au7AwfLMC">
<name>Killed Banano - Disco Version</name>
<artist href="spotify:artist:2XtRg7z3aq8UsX1fstLJKM">
<name>Hypo</name>
</artist>
<id type="isrc">FR6V80402639</id>
<album href="spotify:album:2r2lvkRFTGXDXfNxUslgv7">
<name>Random Veneziano</name>
<released>2005</released>
<availability>
<territories>
AD AE AF AG AI AL AM AN AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BM BN BO BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IN IO IQ IR IS IT JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR ST SV SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW ZZ
</territories>
</availability>
</album>
<track-number>19</track-number>
<length>130.044000</length>
<popularity>0.02090</popularity>
</track>
<track href="spotify:track:2w2d0WyMqLwMEGZRGMiBDS">
<name>New Disco</name>
<artist href="spotify:artist:5ircLG6gSoS34Dh6AWNc6g">
<name>Estevon</name>
</artist>
<id type="isrc">ushm21309193</id>
<album href="spotify:album:0AGlfBGzKfBLE9fHU6eOHc">
<name>Estevon Presents Hypo-Hybrid</name>
<released>2013</released>
<availability>
<territories>worldwide</territories>
</availability>
</album>
<track-number>13</track-number>
<length>248.847000</length>
<popularity>0.00000</popularity>
</track>
</tracks>
4

1 回答 1

0

如果您只想要第一个曲目名称,那么这应该可以:

(/*[local-name()='tracks']/*[local-name()='track']/*[local-name()='name'])[1]

此外,如果您想忽略名称空间,我建议您使用local-name()而不是name(). 对于您的情况,它的工作原理相同,但如果有命名空间前缀,name()则会返回它,而local-name()永远不会。

于 2013-06-19T02:07:05.343 回答