Reputation: 1848
Given the following XML:
<LiveScores>
<Competition id="4915" name="Comp1" type="Union" group="">
<Match id="1678" round="No Round" period="2" periodMinutes="40" matchTime="H2 40:06" previewArticleID="102948" matchReportArticleID="" status="Complete" alternateId="40790106">
<MatchDate startDateLocal="2010-11-27 20:45:00" startDateUTC="2010-11-27 19:45:00" dayName="Sat" shortDate="27-Nov">2010-11-27 20:45:00</MatchDate>
</Match>
...more matches
</Competition>
<Competition id="4916" name="Comp2" type="Union" group="">
<Match id="1678" round="No Round" period="2" periodMinutes="40" matchTime="H2 40:06" previewArticleID="102948" matchReportArticleID="" status="Complete" alternateId="40790106">
<MatchDate startDateLocal="2010-11-27 20:45:00" startDateUTC="2010-11-27 19:45:00" dayName="Sat" shortDate="27-Nov">2010-11-27 20:45:00</MatchDate>
</Match>
...more matches
</Competition>
...more competitions
</LiveScores>
Given a specified competition id (e.g. 4915), how do I return only the Competition node which has this id and no other competition nodes?
Upvotes: 0
Views: 1430
Reputation: 2562
Parse the xml, and then run an xpath query using the XmlSearch function.
<!--- parse the xml --->
<cfset variables.livescoresXML = xmlParse(xml) />
<!--- run the query for the competition node wit id of 4915 --->
<cfset variables.myElements = XmlSearch(
variables.livescoresXML,
"/LiveScores/Competition[@id=4915]"
) />
Upvotes: 2