XML棘手。我正在尝试使用当前正在进行的体育“匹配”来隔离节点,或者是下一场即将到来的比赛。
thisScheduleXML:
<Data>
<Sport type="Union">
<Schedules>
<Competition id="48" name="SR" type="Union" group="">
<Match id="1684" round="Week 1" previewArticleID="" matchReportArticleID="" status="Upcoming" alternateId="1">
<MatchDate startDateLocal="2011-02-18 19:35:00" dayName="Fri" shortDate="18-Feb">2011-02-18 19:35:00</MatchDate>
<Venue id="30" timeZoneID="NZDT" gmtMinutes="780" venue="Westpac Stadium" location="Wellington">Westpac Stadium, Wellington</Venue>
<HomeTeam id="8" alternateId="428">Hurricanes</HomeTeam>
<AwayTeam id="7" alternateId="427">Highlanders</AwayTeam>
</Match>
<Match id="1685" round="Week 1" previewArticleID="" matchReportArticleID="" status="Upcoming" alternateId="2">
<MatchDate startDateLocal="2011-02-11 19:40:00" dayName="Fri" shortDate="18-Feb">2011-02-11 19:40:00</MatchDate>
<Venue id="160" timeZoneID="AEDT" gmtMinutes="660" venue="AAMI Park" location="Melbourne">AAMI Park, Melbourne</Venue>
<HomeTeam id="76" alternateId="0">Rebels</HomeTeam>
<AwayTeam id="12" alternateId="422">Waratahs</AwayTeam>
</Match>
.. more matches
</Competition>
... more competitions
</Schedules>
</Sport>
</Data>
非常感谢任何正确方向的帮助。 我会想到这些内容:
<cfset currentMatchNode = xmlSearch(thisScheduleXml,"/SportalData/Sport/Schedules/Match/MatchDate[@startLocalDate is current otherwise the next upcoming one]")>
答案 0 :(得分:2)
我找不到在XPath中匹配日期的方法。也许别人可以帮忙。但是,在过去我们使用循环在CF中处理了这个问题。例如:
<cfset nodes = xmlSearch(x, "/Data/Sport/Schedules/Competition/Match") />
<cfset found = false />
<cfloop array="#nodes#" index="match">
<!--- Check to see if the match is on now or in the future --->
<cfif match["MatchDate"].xmlText gte now()>
<cfdump var="#match#" />
<cfset found = true />
</cfif>
<!--- Only output the first --->
<cfif found>
<cfbreak />
</cfif>
</cfloop>
这将打印第一场比赛的Match
节点。希望它能帮助您朝着正确的方向前进。