1 Reply Latest reply on Mar 26, 2008 8:42 PM by ntsiii

    Filter an XMLList based on values stored in an arary

    trainsimple Level 1
      Basically what I want to do is remove elements with in my XMLList if the node contains a specific value. The catch is that value could be a multiple number of different values.

      For example I have an XMLList that has several items:

      <item id="200">
      <url>some.swf</url>
      <image>image.jpg</image>
      <owner id="123" name="Some Company">
      </item>
      <item id="201">
      <url>some.swf</url>
      <image>image.jpg</image>
      <owner id="123" name="Some Company Again">
      </item>


      Then I have an Array that is storing the Companies that I want filtered out of the XMLList .. example:

      filterArray[0] = "Company X";
      filterArray[1] = "Some Company";

      I don't know how many indexes the array will have. What I want to do is delete any item in the XMLList that has a owner.@name that is equal to any name stored in any index of the Array. I have no idea where to start with this. Any help would be great!

        • 1. Re: Filter an XMLList based on values stored in an arary
          ntsiii Level 3
          I'd create a filter function, and in that function, loop over the array, comparing values.

          You can do something like this:

          var xl:XMLList = xmlItems.item.(!isExcluded(*));

          private function isExcluded(xmlItem:XML):Boolean {
          var bExcluded:Boolean = false;
          var sOwnerName:String = xmlItem.owner.text();
          for (var i:int=o;i<aCompanies.length;i++) {
          if (aCompanies [ i ] == sOwnerName) {
          bExcluded = true;
          break;
          }
          return bExcluded;
          }

          Tracy