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

Display Parts of XML Feed in ColdFusion

Community Beginner ,
Apr 23, 2012 Apr 23, 2012

Copy link to clipboard

Copied

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?

Views

834

Translate

Translate

Report

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

Community Expert , Apr 24, 2012 Apr 24, 2012

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.keywords.xmltext, 1)#</cfoutput><br>

</cfloop>

Votes

Translate

Translate
Guest
Apr 24, 2012 Apr 24, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 24, 2012 Apr 24, 2012

Copy link to clipboard

Copied

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.keywords.xmltext, 1)#</cfoutput><br>

</cfloop>

Votes

Translate

Translate

Report

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
Community Beginner ,
Apr 24, 2012 Apr 24, 2012

Copy link to clipboard

Copied

LATEST

YES! That works beautifully BKBK, thank you!!! This will help me a lot!

Votes

Translate

Translate

Report

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
Documentation