Skip to main content
Participant
February 2, 2010
Answered

XML Output with multiple categories

  • February 2, 2010
  • 1 reply
  • 312 views

I am driving myself insane trying to get this to output and I can't seem to find much on the internet that is helpful. Sometimes there is 1 category and sometimes there could be 2.

For example:

<Article>
<Heading>Study: Ban on cell phone use hasn't reduced accident rate</Heading>
<Date>01/02/2010</Date>
<Contents>Content regarding cell phone use.</Contents>
<Categories>
<Category ID="438024898">General Auto News</Category>
<Category ID="438022448">Electronics</Category>
</Categories>
</Article>

I set myitems with the xml search and can manage to output everything below perfectly, except for the multiple categories.

<cfloop from="1" to="#arrayLen(myItems)#" index="i">

#myItems.Heading.xmltext#

#myItems.Categories.Category.xmltext#        this outputs only the first one, but I can not seem to get the second.

</cfloop>

Thanks for any help in advance!!!!

This topic has been closed for replies.
Correct answer ilssac

<cfloop from="1" to="#arrayLen(myItems.Categories.Category#" index="c"

    #myItems.Categories.Category.xmltext#

</cfloop>

OR

#myItems.Categories.Category[1].xmltext#
#myItems.Categories.Category[2].xmltext#

Category is just a nested array just like your myItems was.

Or you could do another xmlSearch if you prefer.

1 reply

ilssac
ilssacCorrect answer
Inspiring
February 2, 2010

<cfloop from="1" to="#arrayLen(myItems.Categories.Category#" index="c"

    #myItems.Categories.Category.xmltext#

</cfloop>

OR

#myItems.Categories.Category[1].xmltext#
#myItems.Categories.Category[2].xmltext#

Category is just a nested array just like your myItems was.

Or you could do another xmlSearch if you prefer.