as3 remove duplicated childs

There are several ways of doing the same thing, the result is the same, I was wandering if there is more efficient way to do this.
Lets say you have xml that looks like:

Actionscript:
  1. var videoXML:XML = <videos>
  2.                         <video title="title 1">
  3.                             <tags>
  4.                                 <tag>Tag 1</tag>
  5.                                 <tag>Tag 2</tag>
  6.                                 <tag>Tag 3</tag>
  7.                             </tags>
  8.                         </video>
  9.                         <video title="title 2">
  10.                             <tags>
  11.                                 <tag>Tag 1</tag>
  12.                                 <tag>Tag 2</tag>
  13.                                 <tag>Tag 4</tag>
  14.                                 <tag>Tag 5</tag>
  15.                             </tags>
  16.                         </video>
  17.                         <video title="title 3">
  18.                             <tags>
  19.                                 <tag>Tag 6</tag>
  20.                                 <tag>Tag 2</tag>
  21.                             </tags>
  22.                         </video>
  23.  
  24.                    </videos>;

And you want to get list of the tags but without duplicates.
so far this is the fastest way I found

Actionscript:
  1. var tags:XMLList=videoXML..tag;
  2. trace("tags="+tags);
  3. var filteredTagsXML:XML = <filters></filters>;
  4.  
  5. for each (var key:* in tags) {
  6.     if (! filteredTagsXML.tag.contains(key)) {
  7.         filteredTagsXML.appendChild(key);
  8.     }
  9. }
  10.  
  11. trace( "filteredTags="+filteredTagsXML.tag);

Any other suggestions, solutions ?
Thx

Bookmark and Share

Releated Posts

0 Responses to “as3 remove duplicated childs”


  • No Comments

Leave a Reply