开发者

How to set a variable attribute of an xml element in actionscript 3?

开发者 https://www.devze.com 2022-12-18 14:14 出处:网络
Something that should be very easy has been the quest of my day. How do you set a variable attribute of a xml element?开发者_JS百科

Something that should be very easy has been the quest of my day.

How do you set a variable attribute of a xml element?

开发者_JS百科

This is what I expected to work:

xmlElement.attribute(variableAttr) = "the variable attribute is set to this string";

However, I'm getting some error that this value can only be retrieved as a reference and not set.

Ofcourse, the following does not work either as it will look for the attribute named "variableAttr" and not for the attribute named after the value of the variable variableAttr:

xmlElement.@variableAttr = "example";


You have to enclose your variable name with square bracket @[my var] :

xmlElement.@[variableAttr] = "example";


Try

xmlElement.attributes.variableAttr = "example";

example code:var d:XMLDocument = new XMLDocument(); var e:XMLNode; d.appendChild(e = d.createElement("Root")); e.attributes.val = "100"; trace(d.toString()); //prints <Root val="100" />

0

精彩评论

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