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"> |
I would like to pull the restaurant name from the feed and display it in a list format
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?
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>
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.
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>
Copy link to clipboard
Copied
YES! That works beautifully BKBK, thank you!!! This will help me a lot!