开发者

Concat E4X expressions in ActionScript 3

开发者 https://www.devze.com 2022-12-28 22:01 出处:网络
Is there any way to concatenate E4X expressions? If I store \"half\" a path in a variable, can I concatenate the way I do with 开发者_JAVA百科Strings?You can always use array access by converting the

Is there any way to concatenate E4X expressions? If I store "half" a path in a variable, can I concatenate the way I do with 开发者_JAVA百科Strings?


You can always use array access by converting the E4X string into an array, seperated by the dots.

var xml:XML = 
    <data>
        <a><b><c><x><y><z attr="This is an attribute">This is a text!</z></y></x></c></b></a>
    </data>

var path1:String = "a.b.c";
var path2:String = "x.y.z";
var path3:String = "@attr";
var path:Array = ([path1, path2, path3].join('.')).split('.');

var result:XMLList = new XMLList(xml);

for (var i:uint = 0; i < path.length; i++) {
    result = result[path[i]];
}

trace(result); // This is an attribute
0

精彩评论

暂无评论...
验证码 换一张
取 消