Solved

Loop over XML in Coldfusion

Posted on 2007-03-27
2
896 Views
Last Modified: 2013-12-24
I have the following variable defined in CF:

<cfset temp="<xmlgrid><data1>aaa</data1><data2>bbb</data2></xmlgrid><xmlgrid><data1>xxx</data1><data2>yyy</data2></xmlgrid>">

How can I loop over this string and show a table containing:
aaa    bbb
xxx    yyy

Everything I have tried failed...
0
Comment
Question by:WebDvlp
2 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 18800046

 have you tried XMLParse(temp) to transform the XML into a structure?
0
 
LVL 12

Accepted Solution

by:
mkishline earned 500 total points
ID: 18800356
gdemaria is right that you'll need to use XMLParse, but first your xml needs to be formatted correctly there needs to be a top-level container around all of your data, like this:

<cfset temp="<xmlcontent><xmlgrid><data1>aaa</data1><data2>bbb</data2></xmlgrid><xmlgrid><data1>xxx</data1><data2>yyy</data2></xmlgrid></xmlcontent>" />

then you can parse your xml and access it like a struct:
<cfset xml = XMLParse(temp) />
<cfset xmlrows = XMLSearch(xml,"//xmlgrid") />

<table cellpadding="5" cellspacing="0">
<cfoutput>
<cfloop index="i" from="1" to="#ArrayLen(xmlrows)#">
      <tr><cfloop index="j" from="1" to="#ArrayLen(xmlrows[i].xmlchildren)#"><td>#xmlrows[i].xmlchildren[j].xmlText#</td></cfloop></tr>
</cfloop>
</cfoutput>
</table>
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question