Skip to main content

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.

XML
<set var="firstname">Bill</set>
<set var="lastname">Gates</set>
<output>$firstname $lastname</output>
<!-- Bill Gates -->

Setting array items — these three forms are equivalent:

XML
<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:

XML
<set var="list[]">first</set>
<set var="list[]">second</set>

Full reference →


unset — Remove variable

Removes a variable entirely, making it undefined. Different from setting to NULL or empty string.

XML
<set var="x">hello</set>
<unset var="x"/>
<!-- typeof is now 'undefined' -->

Full reference →


null / true / false — Set typed values

Set a variable to a specific typed value directly:

XML
<null var="x"/> <!-- type: null -->
<true var="flag"/> <!-- type: bool, value: TRUE -->
<false var="off"/> <!-- type: bool, value: FALSE -->

null | true | 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.

XML
<set var="name1">iXML</set>
<assign var="name2" var_source="name1"/>
<output>$name2</output>
<!-- iXML -->

Full reference →


clone — Independent copy

Creates a shallow copy independent of the original. Essential for arrays where assign would create a shared reference.

XML
<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 -->

Full reference →


swap — Exchange two variables

Exchanges values in a single atomic step:

XML
<set var="a">first</set>
<set var="b">second</set>
<swap var1="a" var2="b"/>
<output>$a, $b</output>
<!-- second, first -->

Full reference →


cast — Type conversion

Converts a variable to a specified data type. Essential because <set> always creates strings.

XML
<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.

Full reference →


eval — Evaluate expression

Evaluates a string with variable substitution, resolving references dynamically:

XML
<set var="dollar">$</set>
<set var="name">iXML</set>

<output>
<eval>My name is $dollar$name!</eval>
</output>
<!-- My name is iXML! -->

Full reference →


verbatim — Prevent substitution

Returns content without variable substitution — the opposite of eval:

XML
<output>
<verbatim>Show me the $dollars!</verbatim>
</output>
<!-- Show me the $dollars! -->

Full reference →


global — Declare global variable

Declares a variable with global scope, visible across all contexts including functions and includes:

XML
<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.

Full reference →