Skip to main content
Participant
August 18, 2025
Answered

Display Only Restaurant Name from XML Feed (ColdFusion)

  • August 18, 2025
  • 1 reply
  • 153 views

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 🙏

    Correct answer daniyal_7136

    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.

    1 reply

    daniyal_7136Correct answer
    Participant
    August 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")>

    <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.