SO : Dyn XML query

by pleclech forked from forked from: SO xml namespace attributes access (diff: 34)
♥0 | Line 40 | Modified 2012-10-18 20:42:36 | MIT License
play

ActionScript3 source code

/**
 * Copyright pleclech ( http://wonderfl.net/user/pleclech )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ltN2
 */

package {
    import flash.events.Event;
    import flash.utils.setTimeout;
    import com.bit101.components.TextArea;
    
    public class FlashTest extends TextArea {
        public function FlashTest() {
            width=400
            height=400
            setTimeout(doTest, 500)                        
        }
        public function doTest():void {
            try {
                var xmlData:XML = <game playGame="true" name="peopleNames" id="1">
      <category publish="pubTrue" categoryName="guys" categoryNumber="1">
        <word wordName="ross"/>
        <word wordName="chandler"/>
        <word wordName="joey"/>
      </category>
    <category publish="pubTrue" categoryName="girls" categoryNumber="2">
        <word wordName="rachel"/>
        <word wordName="monica"/>
        <word wordName="phoebe"/>
    </category>
</game>;

var insQuery4b:* = xmlData.(@id=='1').category.(@categoryNumber=='1').(@publish=='pubTrue').word.@wordName[0];
trace(insQuery4b.toString());

var i:int = 2;
// with explicit cast
var insQuery4a:String = xmlData.(@id=='1').category.(@categoryNumber==i.toString()).(@publish=='pubTrue').word.@wordName[0];
trace(insQuery4a);

// with implicit cast
var insQuery4c:String = xmlData.(@id=='1').category.(@categoryNumber==i).(@publish=='pubTrue').word.@wordName[0];
trace(insQuery4c);

            } catch (e:*) {
                trace(e);
            }
        }

        public function trace(...args):void {
            text=text+args.join(", ")+"\n"
        }
    }
}

Forked