Array Construction
array — Build array
The ARRAY command is the primary mechanism for constructing structured data in iXML. It creates an associative array (a collection of key-value pairs) and binds it to a variable.
Syntax
XML
<array var="variableName">
<item key="key1">value1</item>
<item key="key2">value2</item>
</array>
Attributes
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
var | var | Yes | — | The variable name to bind the resulting array to. |
key | string | No | (next consecutive numeric key) | When used as a nested element, specifies the key in the parent array. |
Examples
Array with explicit string keys:
XML
<array var="names">
<item key="bg">Bill Gates</item>
<item key="sj">Steve Jobs</item>
</array>
<output>$names.bg and $names.sj are competitors!</output>
Array with implicit numeric keys:
XML
<array var="names">
<item>Bill Gates</item>
<item>Steve Jobs</item>
</array>
<output>$names[0] and $names[1] are competitors!</output>
item — Array item
The ITEM command defines a single key-value pair within an <array> construct.
Syntax
XML
<item key="keyName">value</item>
<item>value</item>
Attributes
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
var | var | No | — | Variable name. When specified, the item's value is also stored in this variable independently. |
key | string | No | (next consecutive numeric key) | The key for this item within the parent array. |
array:range — Create numeric range array
The ARRAY:RANGE command creates an array populated with values from a numeric range.
Syntax
XML
<array:range var="variableName" from="start" to="end" />
<array:range var="variableName" from="start" to="end" step="increment" />
Attributes
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
var | var | Yes | — | The variable name to bind the resulting array to. |
from | int | Yes | — | The starting value of the range (inclusive). |
to | int | Yes | — | The ending value of the range (inclusive). |
step | int | No | 1 | The increment between consecutive values. |
Example
XML
<array:range var="range" from="6" to="10" step="2" />
<!-- Result: [6, 8, 10] -->
array:assoc — Associate keys and values
The ARRAY:ASSOC command creates a new associative array by combining parallel arrays of keys and values.
Syntax
XML
<array:assoc var="result" var_keys="keysArray" var_values="valuesArray" />
Example
XML
<array var="keys"><item>bg</item><item>sj</item></array>
<array var="values"><item>Bill Gates</item><item>Steve Jobs</item></array>
<array:assoc var="names" var_keys="keys" var_values="values" />
<!-- Result: {"bg": "Bill Gates", "sj": "Steve Jobs"} -->
array:populate — Import array into variable scope
The ARRAY:POPULATE command takes all key-value pairs from an array and imports them into the local variable scope as individual variables.
Syntax
XML
<array:populate var="sourceArray" prefix="prefix_" />
Attributes
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
var | var | Yes | — | The source array. |
prefix | string | No | — | A prefix prepended to each key to form the variable name. |
Example
XML
<array var="data"><item key="id">123</item></array>
<array:populate var="data" prefix="user_" />
<output>User ID: $user_id</output>