Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Loop over XML in Coldfusion

Posted on 2007-03-27
2
895 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coldfusion update database with CFLOOP 5 64
JKS to store upstart data 2 105
CFFILE upload help 98 169
whm high memory usage in processes 7 103
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

791 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