2011-02-17 3 views
3

XML 교묘함. 나는 현재 진행중인 스포츠 "Match"로 노드를 격리하려고하거나 다음 다가올 경기입니다.coldfusion + 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> 

. 나는이 라인을 따라 뭔가 생각했을 것이다 : 나는 XPath는 날짜에 일치 할 수있는 방법을 찾을 수 없습니다

<cfset currentMatchNode = xmlSearch(thisScheduleXml,"/SportalData/Sport/Schedules/Match/MatchDate[@startLocalDate is current otherwise the next upcoming one]")> 
+0

XMLSearch()가 xpath 날짜 기능을 지원하지 않기 때문에 xpath만으로는 불가능합니다. – orangepips

답변

2

합니다. 어쩌면 다른 사람이 그걸 도울 수 있습니다. 그러나 과거에는 루프를 사용하여 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이 인쇄됩니다. 그것이 올바른 방향으로 당신을 도울 수 있기를 바랍니다.

+0

xpath 날짜 기능이 있습니다. 문제는 이들이 XPath 2.0의 일부이며, ColdFusion (최소 8)은 XPath 1.0 만 지원한다는 것입니다. 이것은 xpath에서 문자열 파싱으로 수행 할 수 있지만 문제는 시간대에 따라 복잡합니다. 여기에 제안 된 cf 코드가 올바른 접근 방법 일 수 있지만 시간대를 고려하여 수정해야합니다. http://www.w3schools.com/Xpath/xpath_functions.asp#datetime – Mark

관련 문제