Skip navigation
Currently Being Moderated

Display Parts of XML Feed in ColdFusion

Apr 23, 2012 6:01 PM

Tags: #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">
<food id="bk101">
<keywords>Burger King, pie, hamburgers, fries, milkshakes</keywords>
<food id="bk102">
<keywords>Taco Bell, tacos, churros, burrito, gorditas</keywords>
<food id="bk103">
<keywords>Pizza Hut, pizza, cheese, garlic bread</keywords>
<food id="bk104">
<keywords>Chick-Fil-A, chicken, chicken wrap, sauce, Bananas Pudding Milkshake</keywords>


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

  • Burger King
  • Taco Bell
  • Pizza Hut
  • Chick-Fil-A

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?

  • Currently Being Moderated
    Apr 24, 2012 1:48 AM   in reply to mikesorako

    Assuming that your xml comes allways in that form (the name of the restaurant being the first in the string and everything is separeted by ",") you can do it like this:


          text = "Pizza Hut, pizza, cheese, garlic bread";
          array = text.split(",");


    The name of the restaurant will be in the array[1].


    I dont know if the xml feed is done by you and i also dont know the context of your application but might be good to change it.



    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 9:51 AM   in reply to mikesorako

    You're already on your way with XML, so use XML syntax:


    <cfloop from="1" to="#arrayLen(" index="i">

    <cfoutput>#listGetAt([i].keywords.xmltext, 1)#</cfoutput><br>


    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points