Q:

How To filter a HierarchicalCollectionView in flex

I have an hierarchical xml structure like this:
<employee name="AAA" group="1"..../>
    <employee name="BBB" group="1"...>
        <employee name="CCC" group="1".../>
     </employee>  
    <employee name="DDD" group="0"... />
    <employee name="EEE" group="0"... />
</employee>

I load the XML, and then pass the data to an hierarchicalcollectionview:
var model:XML = .... (load the data)
var hData:HierarchicalData = new HierarchicalData(model);           
hCol = new HierarchicalCollectionView(hData);

Then, I use hCol as dataProvider for a custom component. That component does not support dataDescriptor
I want to show only the items with attribute group="1". (AAA, BBB and CCC in this example)
How can I do it? I tested with the filterFunction property but it only filters the root node (I think)
I have to filter all the XML items by that attribute
Thanks in advance
Cristian

A:

I use this to filter my XML tree, except I only show the final nodes that match the search I am running.  You can modify it to return nodes with children as well, but it gives you something to go on instead of HiearchicalCollection
private function filterXML(itemXML:XML, mainXML:XML, text:String) : XML {
            if(itemXML.hasComplexContent()) {
                for each(var childXML : XML in itemXML.children()) {
                    filterXML(childXML, mainXML, text);
                }
            } else {
                var regex :RegExp = new RegExp(text, "gi");
                if(itemXML.@group.toXMLString().search(regex)!=-1){
                    mainXML.appendChild(itemXML);
                }
            }
            return mainXML;
        }

