开发者

How to access the value of an XML attribute using a String variable? How can this be applied to filtering?

Using e4x in flex:

var attr : String = "foo";
var xml : XML = 
    <resultSet>
       <node foo="1"/>
    </resultSet>;

How can I use the variable "attr" to access

xml.node.@foo 

I thought I could do it with 开发者_JAVA百科

xml.node.@[attr]

But this doesn't seem to work. How can I access this attribute by a dynamic value like this?

EDIT: Both

xml.node.@[attr];

and

xml.node.attribute(attr);

work, as Constantiner suggested.

Updates:

Say I have an XMLList in this form:

var bar:XML = 
    <resultSet>
         <node>value</node>
    </resultSet>;

I want to filter the original xml above by matching "foo" attributes with the "value" from node in bar.

Essentially I want a sublist of the original xml such that

xml.node.@foo == bar.value 

for each xml row in the original value

As Constantiner mentioned, I can filter the original list by the value in foo, but what if I want to filter on multiple values?

Can I do something like:

xml.node.(bar.node.contains(attribute(foo)) ? attribute(foo) : null);

Or perhaps a cleaner method instead of the null?


Try to use xml.node.attribute(attr).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜