• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Looping through xml in cfscript

Explorer ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

Ok, I can loop through xml to get the value of any tag and output it to a variable. But the problem for me is getting the child tags of a specific tag to loop out grouped together. For instance, below I would want to group the xml like this.

Year: 90
Employer: Bank
Wages: 2000.00

Year: 90
Employer: Gas Station
Wages: 1000.00

Ok, I can loop through xml to get the value of any tag and output it to a variable. But the problem for me is getting the child tags of a specific tag to loop out grouped together. For instance, below I would want to group the xml like this.

Year: 91
Employer: Bank
Wages: 2500.00

Year: 91
Employer: Gas Station
Wages: 1500.00


<year value="90">
<employer name="bank">
<wages>2000.00</wages>
</employer>
<employer name="gas station">
<wages>1000.00</wages>
</employer>
</year>

<year value="91">
<employer name="bank">
<wages>2500.00</wages>
</employer>
<employer name="gas station">
<wages>1500.00</wages>
</employer>
</year>

Thanks in advanced,

Anthony
TOPICS
Advanced techniques

Views

645

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 19, 2007 Mar 19, 2007
This might be easier with a query. Create one with QueryNew(), and populate it when you loop through the xml. Then use Q of Q to sort it by employer, then year. You can now use the group attribute of cfoutput to group by employer.

Votes

Translate

Translate
LEGEND ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

Will this xml always be sorted by year?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

It will always be sorted by year and by employer. I was just trying to get the basic concept of the looping and would figure the rest out myself. But I would want it to look like this.

Employer: Bank
Year: 90 Wages: 2000.00
Year: 91 Wages: 2500.00

Employer: Gas Station
Year: Wages: 1000.00
Year: Wages: 1500.00


Thanks in advance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

This might be easier with a query. Create one with QueryNew(), and populate it when you loop through the xml. Then use Q of Q to sort it by employer, then year. You can now use the group attribute of cfoutput to group by employer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 19, 2007 Mar 19, 2007

Copy link to clipboard

Copied

LATEST
Thanks alot. That is perfect. Much easier.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation