Elements and attributes can be associated with iterators, either by
listening to them, or by calling next() on them directly. The
next two examples show elements that call next() directly. The
containers example uses listeners.
The first example has one element, and generates:
10 11 12 13 14 15 16 17 18 19
The element named element0 writes to writer0,
which writes to stdout. The output format is CSV, defined by
formatter0. The element's attribute gets its values by calling
next() on iter0.
<dm:ints range="[10]">
<dm:iterator id="iter0"/>
</dm:ints>
<dmio:stream-writer id="writer0" stream="stdout"/>
<dmio:csv-format id="formatter0"/>
<dmio:element id="element0" writer="writer0" formatter="formatter0">
<dmio:attribute iterator="iter0"/>
</dmio:element>
In this next example, element1 writes to stdout in XML
format. Each XML element that is output is named A. The element
has four attributes:
a, and gets its values by
calling next() on an embedded collection whose range is
[10]2.
b, and gets its values from the
iterator whose id is iter1.
c, and gets its values from an
iterator on the ints collection whose id is
ints1.
d, and gets its values from the
same iterator as attribute b. Note that it gets the
iterator's current value, and so writes the same value as b.
<dm:ints id="ints1" range="[10]3">
<dm:iterator id="iter1"/>
</dm:ints>
<dmio:element id="element1" name="A">
<dmio:stream-writer stream="stdout"/>
<dmio:xml-format/>
<!-- a -->
<dmio:attribute name="a">
<dm:ints range="[10]2"/>
</dmio:attribute>
<!-- b -->
<dmio:attribute name="b" iterator="iter1"/>
<!-- c -->
<dmio:attribute name="c">
<dm:iterator collection="ints1"/>
</dmio:attribute>
<!-- d -->
<dmio:attribute name="d" iterator="iter1" current="true"/>
</dmio:element>
The result is:
<A a="10" b="10" c="10" d="10"/>
<A a="12" b="13" c="13" d="13"/>
<A a="14" b="16" c="16" d="16"/>
<A a="16" b="19" c="19" d="19"/>
<A a="18" b="22" c="22" d="22"/>
<A a="20" b="25" c="25" d="25"/>
<A a="22" b="28" c="28" d="28"/>
<A a="24" b="31" c="31" d="31"/>
<A a="26" b="34" c="34" d="34"/>
<A a="28" b="37" c="37" d="37"/>