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:
-
var videoXML:XML = <videos>
-
<video title="title 1">
-
<tags>
-
<tag>Tag 1</tag>
-
<tag>Tag 2</tag>
-
<tag>Tag 3</tag>
-
</tags>
-
</video>
-
<video title="title 2">
-
<tags>
-
<tag>Tag 1</tag>
-
<tag>Tag 2</tag>
-
<tag>Tag 4</tag>
-
<tag>Tag 5</tag>
-
</tags>
-
</video>
-
<video title="title 3">
-
<tags>
-
<tag>Tag 6</tag>
-
<tag>Tag 2</tag>
-
</tags>
-
</video>
-
-
</videos>;
And you want to get list of the tags but without duplicates.
so far this is the fastest way I found
Actionscript:
-
var tags:XMLList=videoXML..tag;
-
trace("tags="+tags);
-
var filteredTagsXML:XML = <filters></filters>;
-
-
for each (var key:* in tags) {
-
if (! filteredTagsXML.tag.contains(key)) {
-
filteredTagsXML.appendChild(key);
-
}
-
}
-
-
trace( "filteredTags="+filteredTagsXML.tag);
Any other suggestions, solutions ?
Thx
0 Responses to “as3 remove duplicated childs”