1 Reply Latest reply on Feb 2, 2010 2:16 PM by ilssac

    XML Output with multiple categories

    annamjmi

      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[i].Heading.xmltext#

      #myItems[i].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!!!!

        • 1. Re: XML Output with multiple categories
          ilssac Level 5
          <cfloop from="1" to="#arrayLen(myItems[i].Categories.Category#" index="c"
              #myItems[i].Categories.Category[c].xmltext#
          </cfloop>
          

           

          OR

           

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

           

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

           

          Or you could do another xmlSearch if you prefer.