3 Replies Latest reply on Jan 9, 2008 10:11 PM by Anibus100

    XML for each in ..Loop statement

    Anibus100
      Happy New Year,

      I just got XML to trace my desired results…Wow….

      But I need help in the.....

      Var c:Number = 0
      Var total:Number = 0
      for each (var property:XML in getPaid.revenue)
      {
      c = c +1
      }
      trace("total: " + c);
      The total is true or what I was looking for….

      Next….
      var c:Number = 0;
      for each (var property:XML in getPaid.revenue.(elements('revType') == 'Performance')

      {
      c = c +1
      }
      trace("total: " + c);
      This works too.

      BUT!
      for each (var property:XML in getPaid.revenue.(elements('revType') == 'Performance')
      {

      c = c +1

      trace (c + " Song Title: " + getPaid.revenue.revTitle[c]
      + " Song Type: " + getPaid.revenue.revType[c]
      + " Total Amount: " + getPaid.revenue.revAmount[c]
      + " Account Name: " + getPaid.revenue.revName[c]);


      }
      trace("total: " + c);

      Here the total is correct but if the total is 2 I get 3 items listed in the trace…even if I move the counter (c=c+1) below the trace statement…Help!

      Next…..


      for each (var property:XML in getPaid.revenue.(elements('revType') == 'Performance')
      && getPaid.revenue.(elements('revTitle') == 'Sister Love'))
      {
      c = c +1
      }
      trace("total: " + c);

      Here the second conditional is not seen……. Help…

      Next

      Var total:Number = 0
      for each (var property:XML in getPaid.revenue)
      {
      c = c +1

      if (getPaid.revenue.(revTitle == "Sister Love"))
      {
      d = d + 1;
      trace("total:" + c + getPaid.revenue.revTitle);
      }

      }
      trace("total: " + c);

      Here The if conditional isn’t seen…..
      What is the optimal way the read elements in the for each loop to test for two conditions.

      Sincerely,
      Anibus100
      PS Please show the answer in code…..


      XML Object

      var getPaid:XML = <revData>
      <revenue>
      <revName>KJAZZ</revName>
      <revTitle>Sister Love</revTitle>
      <revAmount>4,000.00</revAmount>
      <revDateIn>12/20/1990</revDateIn>
      <revDateOut>12/20/2009</revDateOut>
      <revType>Performance</revType>
      <revDescript>Radio Play</revDescript>
      </revenue>
      <revenue>
      <revName>J Records</revName>
      <revTitle>Sister Love</revTitle>
      <revAmount>85,000.00</revAmount>
      <revDateIn>1/4/1969</revDateIn>
      <revDateOut>1/4/1972</revDateOut>
      <revType>Mechanical</revType>
      <revDescript>CD License</revDescript>
      </revenue>
      <revenue>
      <revName>KDAY</revName>
      <revTitle>Get The Money</revTitle>
      <revAmount>3000.00</revAmount>
      <revDateIn>12/20/2003</revDateIn>
      <revDateOut>12/20/2003</revDateOut>
      <revType>Performance</revType>
      <revDescript>Radio Play</revDescript>
      </revenue>
      <revenue>
      <revName>AT&T</revName>
      <revTitle>Sister Love</revTitle>
      <revAmount>697.00</revAmount>
      <revDateIn>5/13/2006</revDateIn>
      <revDateOut>5/13/2008</revDateOut>
      <revType>New Media</revType>
      <revDescript>Cell Phone Ring Tone</revDescript>
      </revenue>
      <revenue>
      <revName>CBS TV</revName>
      <revTitle>Get The Money</revTitle>
      <revAmount>150,000.00</revAmount>
      <revDateIn>5/8/1988</revDateIn>
      <revDateOut>7/15/1988</revDateOut>
      <revType>Snychronzation</revType>
      <revDescript>TV China Beach</revDescript>
      </revenue>
      <revenue>
      <revName>Soul Train</revName>
      <revTitle>The Money</revTitle>
      <revAmount>7,000.00</revAmount>
      <revDateIn>2/25/2001</revDateIn>
      <revDateOut>2/25/2001</revDateOut>
      <revType>Synchronzation</revType>
      <revDescript>Radio Play</revDescript>
      </revenue>
      <revenue>
      <revName>Sheet Music Inc</revName>
      <revTitle>Sister Love</revTitle>
      <revAmount>450.00</revAmount>
      <revDateIn>12/20/1990</revDateIn>
      <revDateOut>12/20/1990</revDateOut>
      <revType>Performance</revType>
      <revDescript>Radio Play</revDescript>
      </revenue>
      <revenue>
      <revName>Town & Country </revName>
      <revTitle>Get The Money</revTitle>
      <revAmount>1,500.00</revAmount>
      <revDateIn>3/3/1998</revDateIn>
      <revDateOut>12/20/2009</revDateOut>
      <revType>New Media</revType>
      <revDescript>Web Site Intro. Music</revDescript>
      </revenue>
      <revenue>
      <revName>R & B Tee-Shirts, Inc</revName>
      <revTitle>Get The Money</revTitle>
      <revAmount>475.00</revAmount>
      <revDateIn>8/14/2006</revDateIn>
      <revDateOut>8/14/2008</revDateOut>
      <revType>Print</revType>
      <revDescript>Tee Shirt Logo</revDescript>
      </revenue>
      </revData>;