Mike
Mike

Reputation: 967

Display Parts of XML Feed in ColdFusion

I am working with ColdFusion/XML and would like to display restaurant names in my application. The problem is the restaurant names are part of the keywords field and are included with a list of foods the restaurant serves.

<cfxml variable="eating">
<catalog>
<food id="bk101">
  <author>Burgers</author>
  <keywords>Burger King, pie, hamburgers, fries, milkshakes</keywords>
</food>
<food id="bk102">
  <author>Mexican</author>
  <keywords>Taco Bell, tacos, churros, burrito, gorditas</keywords>
</food>
<food id="bk103">
  <author>Pizza</author>
  <keywords>Pizza Hut, pizza, cheese, garlic bread</keywords>
</food>
<food id="bk104">
  <author>Chicken</author>
  <keywords>Chick-Fil-A, chicken, chicken wrap, sauce, Bananas Pudding Milkshake</keywords>
</food>
</catalog>
</cfxml>

I would like to pull the restaurant name from the feed and display it in a list format

The XML feed above is simplified, and I have a few hundred of that kind of data to display. Luckily the restaurant name is always listed first in the keyword field followed by the food. How can pull and display the restaurant names only from the XML feed above?

Upvotes: 0

Views: 245

Answers (1)

Paul
Paul

Reputation: 1575

<cfset data = xmlSearch(eating,"//food") />
<cfloop array="#data#" index="i" >
        <cfoutput>#listFirst(xmlSearch(i,"keywords")[1].xmlText)#</cfoutput><br/>
</cfloop>

Should do it.

Upvotes: 5

Related Questions