set

The set verb does just what it might be expected to do: it sets a variable. It has two required attributes, name and value. Here are some examples:

<set name="color" value="red" />
<set name="#color#" value="maroon" />
<set name="deepred" value="dark#color#" />

The first statement sets the variable, color, to the value, red. The second statement sets the variable, red, to the value maroon and the third statement sets the variable, deepred, to the value, darkred. All operate the same way you would expect dynamic variable setting in ColdFusion, the only restriction being that imposed by compliancy with XML rules wherein a limited set of characters, such as the ampersand (&), must be specified by their character entities, such as '&'.

The set command also has an optional Boolean attribute of overwrite that is true by default. If you set it to false such as:

<set name="color" value="red" overwrite="false" />

then the variable will only be set if the variable is not defined when this command is encountered at runtime.

As you may expect, you can easily scope variables in a set command. Here are some examples:

<set name="session.isAuthenticated" value="TRUE" />
<set name="form.country" value="USA" />
<set name="attributes.userName" value="Joe" />

Additional Information