I'm working on an application for a client that keeps track of movies in an xml driven database. I can read/write to the xml file fine, but I wanted to optimize the "sorting" of his collection in the display to increase performance a bit more.

There happens to be 3 separate list boxes, a button, and a check box. The first drop down contains different genre names (i.e: comedy, drama, action, adventure, etc), or the word "All" which simply means to use the entire database and should be disregarded hereafter.

The next drop down contains a few more categories: Director, Actor, and Studio.

The third drop down is conditional: if the user leaves the above drop down blank, this one doesn't appear. If it does appear, it is populated by a list of every unique director, actor, or publishing studio (respective to what the second list has selected). So if director is selected, you might see John Woo in there or something. If it's actor, you might find Matt Damon, etc etc.

The last thing is the check box. This is just a small thing and all it does is specify the sort should contain only-new (read: unseen) movies or not.

There's also the Sort button which performs the action.



My problem is in defining a single function for repetitive use that can filter the XML list of <movie>'s repeatedly. Here's an example of the XML structure:


<movie>
<title></title>
<releasedate></releasedate>
<studio></studio>
<runtime></runtime>
<rating></rating>
<imagepath></imagepath>
<moviepath></moviepath>
<format></format>
<prating></prating>
<apppath></apppath>
<desc></desc>
<actor></actor>
<actor></actor>
<actor></actor>
<actor></actor>
<actor></actor>
<director></director>
<genre></genre>
<genre></genre>
<id></id>
<seen></seen>
</movie>
I have removed all the content to make it more clear, but please note that every single attribute of <movie> is treated as a string.

So, this is as far as I have gotten with a function that theoretically should do what I want, but I am stuck with dynamically targeting the nodes.

Actionscript Code:
public function convert(dcl:XMLList) {
            var dcr:XML = new XML(<records></records>);
            var dca:Array = new Array();
           
            for each (item in dcl) {
                dca.push(item);
            }
           
            dca.sortOn("title");
            for (var i = 0; i<dca.length; i++) {
                dcr.appendChild(new XML(dca[i]));
            }
            trace("Convert: " + dcr.movie.length());
            return dcr;
        }

        public function getDataCopy() {
            var dcl:XMLList = data.records.children();
            return dcl;
        }

        public function filter(s1:String, target:String) {
            var dcl:XMLList = getDataCopy();
            dcl = dcl.(target.contains(s1)); // HERE IS WHERE IT ALL GOES WRONG
            trace("Filter: " + dcl.length());
            return dcl;
        }

// EXAMPLE USAGE:
// used to return an XML object to the display class for processing

var returnData:XML = convert(filter("Action", "genre")); // these two strings are normally dynamically passed variables from whatever the user has selected in the drop down list boxes.

In the above code in the filter() function, I can not seem to find a way to dynamically target the attribute of <movie>. The reason I need it in that fashion-- dcl.(target.contains(s1));-- is because I need to return -all- movies whose "target" attribute matches s1, and not just one.

I have seriously scoured the internet for a little over a week now and have have already asked a few other people. Nobody seems to know how to get the target variable to seen as, for instance, the <genre> or <director> or <actor> attribute.

Any help is extremely appreciated... sorry for the long post but I wanted to be clear!