Skip navigation
mikesorako
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">
<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 

  • 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?

 
Replies
  • 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:

     

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

     

    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.

     

    Regards.

     
    |
    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(eating.catalog.food)#" index="i">

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

    </cfloop>

     
    |
    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