Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Loop over XML in Coldfusion

Posted on 2007-03-27
2
Medium Priority
?
902 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
[X]
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
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 2000 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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

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…
What You Need to Know when Searching for a Webhost Provider
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

721 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