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

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

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";

```

Answer: 
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" />`