Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Display Only Restaurant Name from XML Feed (ColdFusion)

New Here ,
Aug 18, 2025 Aug 18, 2025

Hi everyone,

I’m working on a small food-related project in ColdFusion where I need to pull menu data from an XML feed. The feed has both restaurant names and menu items mixed into one "keywords" field.

Here’s a simplified version of the XML:

<cfxml variable="menu">
<catalog>
<food id="cs101">
<author>Chicken</author>
<keywords>Chicken Salad Chick, Classic Carol, Lauryn’s Lemon Basil, Cranberry Kelli</keywords>
</food>
<food id="cs102">
<author>Deli</author>
<keywords>Subway, Italian BMT, Turkey Breast, Tuna, Veggie Delight</keywords>
</food>
</catalog>
</cfxml>

What I’d like to do is just display the restaurant name (always the first value in the keyword string) and ignore the rest.

Desired Output:
Chicken Salad Chick
Subway

For context, the real data comes from a food blog project I’m building: https://chickensaladchicksmenu.com

Any help or code snippet would be awesome 🙏

134
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

New Here , Aug 18, 2025 Aug 18, 2025

You can solve this by just taking the first item from the keywords list. ColdFusion has a built-in function for that:

<cfxml variable="menu">
<catalog>
<food id="cs101">
<author>Chicken</author>
<keywords>Chicken Salad Chick, Classic Carol, Lauryn’s Lemon Basil, Cranberry Kelli</keywords>
</food>
<food id="cs102">
<author>Deli</author>
<keywords>Subway, Italian BMT, Turkey Breast, Tuna, Veggie Delight</keywords>
</food>
</catalog>
</cfxml>

<cfset xmlDoc = menu>
<cfset foods = xmlSearch(xmlDoc, "//food")>

<cfou

...
Translate
New Here ,
Aug 18, 2025 Aug 18, 2025
LATEST

You can solve this by just taking the first item from the keywords list. ColdFusion has a built-in function for that:

<cfxml variable="menu">
<catalog>
<food id="cs101">
<author>Chicken</author>
<keywords>Chicken Salad Chick, Classic Carol, Lauryn’s Lemon Basil, Cranberry Kelli</keywords>
</food>
<food id="cs102">
<author>Deli</author>
<keywords>Subway, Italian BMT, Turkey Breast, Tuna, Veggie Delight</keywords>
</food>
</catalog>
</cfxml>

<cfset xmlDoc = menu>
<cfset foods = xmlSearch(xmlDoc, "//food")>

<cfoutput>
<cfloop array="#foods#" index="f">
#trim(listFirst(f.keywords.xmlText, ","))#<br>
</cfloop>
</cfoutput>


Output:

Chicken Salad Chick
Subway


That should work fine even if your XML has hundreds of <food> nodes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources