Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:10:02+00:00 2026-06-02T15:10:02+00:00

I have the following code. <cfoutput> <cfxml variable=eating> <catalog> <results>10</results> <food id=bk101> <initials>BK</initials> <keywords>Burger

  • 0

I have the following code.

<cfoutput>
<cfxml variable="eating">
<catalog>
<results>10</results>
<food id="bk101">
<initials>BK</initials>
<keywords>Burger King, pie, hamburgers, fries, milkshakes</keywords>
</food>
<food id="bk102">
<initials>TB</initials>
<keywords>Taco Bell, tacos, churros, burrito, gorditas</keywords>
</food>
<food id="bk103">
<keywords>Pizza Hut, pizza, cheese, garlic bread</keywords>
</food>
<food id="bk104">
<initials>CFA</initials>
<keywords>Chick-Fil-A, chicken, chicken wrap, sauce, Bananas Pudding Milkshake</keywords>
</food>
<food id="bk105">
<initials>PE</initials>
<keywords>Panda Express, rice, egg rolls, general tso</keywords>
</food>
<food id="bk106">
<initials>SJ</initials>
<keywords>Sakura Japan, rice, spring rolls, bento</keywords>
</food>
<food id="bk107">
<keywords>Five Guys, fries, burgers, hot dogs</keywords>
</food>
<food id="bk108">
<initials>TN</initials>
<keywords>Tandoori Nights, biryani, chicken, egg rolls</keywords>
</food>
<food id="bk109">
<initials>HoK</initials>
<keywords>House of Kabob, rice, bread, beef kabaob, chicken kabob</keywords>
</food>
<food id="bk110">
<initials>BF</initials>
<keywords>Baja Fresh, quesadilla, soft taco, chili con queso</keywords>
</food>
</catalog>
</cfxml>


<cfset data = queryNew("id,initials,keywords","integer,varchar,varchar")>
<cfloop index="x" from="1" to="#eating.catalog.results.xmlText#">
<cfset queryAddRow(data)>
<cfset querySetCell(data,"id",x)>
<cfset querySetCell(data,"initials","#eating.catalog.food[x].initials#")>
<cfset querySetCell(data,"keywords","#eating.catalog.food[x].keywords#")>
</cfloop>
</cfoutput>

<cfoutput query="data">
#id# - <b>#initials#</b> #keywords#<br />
</cfoutput>

You will notice the initial tags are missing for Elements 3 and 7 in the XML feed . If the initials tags are added to the XML for Elements 3 and 7, the code works beautifully. However since they are missing, this causes CFLoop to throw out an error.

What I would like to do is omit Element 3 (and all other entries which cause an error) from my results and prevent any errors from showing so the application result shows up like so

1 – BK Burger King, pie, hamburgers, fries, milkshakes

2 – TB Taco Bell, tacos, churros, burrito, gorditas

4 – CFA Chick-Fil-A, chicken, chicken wrap, sauce, Bananas Pudding Milkshake

5 – PE Panda Express, rice, egg rolls, general tso

6 – SJ Sakura Japan, rice, spring rolls, bento

8 – TN Tandoori Nights, biryani, chicken, egg rolls

9 – HoK House of Kabob, rice, bread, beef kabaob, chicken kabob

10 – BF Baja Fresh, quesadilla, soft taco, chili con queso

The above feed is a simplified example, my actual feed has hundreds of elements. With that in mind, how can I omit any Elements that give me an error, while still including the elements that do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:10:04+00:00Added an answer on June 2, 2026 at 3:10 pm

    Mike, I copied all your code into a local script to run a quick test. I made the one minor edit to your CFLOOP code and was about to get the output with no errors (added a conditional evaluating the struct to ensure that the key exists with structKeyExists):

    <cfloop index="x" from="1" to="#eating.catalog.results.xmlText#">
        <cfif structKeyExists(eating.catalog.food[x],"initials")>
            <cfset queryAddRow(data)>
            <cfset querySetCell(data,"id",x)>
            <cfset querySetCell(data,"initials", eating.catalog.food[x].initials )>
            <cfset querySetCell(data,"keywords", eating.catalog.food[x].keywords )>
        </cfif>
    </cfloop>
    

    Here is the output I received in my browser:

    1 – BK Burger King, pie, hamburgers, fries, milkshakes

    2 – TB Taco Bell, tacos, churros, burrito, gorditas

    4 – CFA Chick-Fil-A, chicken, chicken wrap, sauce, Bananas Pudding Milkshake

    5 – PE Panda Express, rice, egg rolls, general tso

    6 – SJ Sakura Japan, rice, spring rolls, bento

    8 – TN Tandoori Nights, biryani, chicken, egg rolls

    9 – HoK House of Kabob, rice, bread, beef kabaob, chicken kabob

    10 – BF Baja Fresh, quesadilla, soft taco, chili con queso

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
I have following code class User attr_accessor :name end u = User.new u.name =
i have following code to show div on page <div id=all_users> <div id=user11 userid=11
We have following code: try { // some code throwing MyException } catch (MyException
I have following code snippet that i use to compile class at the run
I have following code: public static void ProcessStep(Action action) { //do something here if
I have following code: private void ProcessQueue() { foreach (MessageQueueItem item in GetNextQueuedItem()) PerformAction(item);
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.