Variables
set — Set variable
The most fundamental command in iXML. Assigns a string value to a variable, creating it if it doesn't exist. The value is always of type string unless replaced by an embedded statement via result propagation.
<set var="firstname">Bill</set>
<set var="lastname">Gates</set>
<output>$firstname $lastname</output>
<!-- Bill Gates -->
Setting array items — these three forms are equivalent:
<set var="names[bg]">Bill Gates</set>
<set var="names.sj">Steve Jobs</set>
<set var="names" key="le">Larry Ellison</set>
Auto-increment key with empty brackets:
<set var="list[]">first</set>
<set var="list[]">second</set>
unset — Remove variable
Removes a variable entirely, making it undefined. Different from setting to NULL or empty string.
<set var="x">hello</set>
<unset var="x"/>
<!-- typeof is now 'undefined' -->
null / true / false — Set typed values
Set a variable to a specific typed value directly:
<null var="x"/> <!-- type: null -->
<true var="flag"/> <!-- type: bool, value: TRUE -->
<false var="off"/> <!-- type: bool, value: FALSE -->
assign — Type-preserving assignment
Copies a value from one variable to another, preserving the original data type. Complex types (arrays, functions) are assigned by reference.
<set var="name1">iXML</set>
<assign var="name2" var_source="name1"/>
<output>$name2</output>
<!-- iXML -->
clone — Independent copy
Creates a shallow copy independent of the original. Essential for arrays where assign would create a shared reference.
<array var="original">
<item>Bill Gates</item>
<item>Steve Jobs</item>
</array>
<clone var="original" var_result="copy"/>
<set var="copy[1]">Larry Ellison</set>
<output>$original[1] and $copy[1]</output>
<!-- Steve Jobs and Larry Ellison -->
swap — Exchange two variables
Exchanges values in a single atomic step:
<set var="a">first</set>
<set var="b">second</set>
<swap var1="a" var2="b"/>
<output>$a, $b</output>
<!-- second, first -->
cast — Type conversion
Converts a variable to a specified data type. Essential because <set> always creates strings.
<set var="number">123</set>
<cast var="number" type="int"/>
<is var="number" type="int">
<output>$number is now an integer!</output>
</is>
Supported types: bool, int, float, string. See Type Conversion for conversion rules.
eval — Evaluate expression
Evaluates a string with variable substitution, resolving references dynamically:
<set var="dollar">$</set>
<set var="name">iXML</set>
<output>
<eval>My name is $dollar$name!</eval>
</output>
<!-- My name is iXML! -->
verbatim — Prevent substitution
Returns content without variable substitution — the opposite of eval:
<output>
<verbatim>Show me the $dollars!</verbatim>
</output>
<!-- Show me the $dollars! -->
global — Declare global variable
Declares a variable with global scope, visible across all contexts including functions and includes:
<global var="appName"/>
<set var="appName">MyApp</set>
<function var="showName">
<output>$appName</output>
</function>
<call func="showName"/>
<!-- MyApp -->
Use sparingly — prefer passing data as parameters.