XML trickiness. I'm trying to isolate开发者_JAVA技巧 the node with a sports "Match" that is currently in progress or is the next upcoming Match.
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>
Any help in the right direction would be greatly appreciated. I would have thought something along these line:
<cfset currentMatchNode = xmlSearch(thisScheduleXml,"/SportalData/Sport/Schedules/Match/MatchDate[@startLocalDate is current otherwise the next upcoming one]")>
I couldn't find a way to match on date in XPath. Maybe someone else can help with that. However, in the past we've dealt with this in CF, using a loop. For example:
<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>
That will print the Match
node of the first match coming up. Hope it helps you in the right direction.
精彩评论