I/O Read

A value list can be associated with an I/O attribute, by listening to it. The next example shows an element that reads values from a file, and three lists that listen to the element's attributes, and load the values read from the file.

The file contains:

    10,11,12
    13,14,15
    16,17,18
  

The three lists are declared first. The element is declared next, and its attributes add the lists as listeners.

    
    <!-- lists -->
    <dm:values id="list0"/>
    <dm:values id="list1"/>
    <dm:values id="list2"/>

    <!-- writer writes by listening to an iterator, and has an attribute
	 that gets its value by listening to the same iterator. -->
    <dmio:element id="element">
      <dmio:file-reader path="testRead.csv"/>
      <dmio:csv-format/>

      <dmio:attribute>
	<dm:listener listener="list0" event="next" action="addValue"/>
      </dmio:attribute>

      <dmio:attribute>
	<dm:listener listener="list1" event="next" action="addValue"/>
      </dmio:attribute>

      <dmio:attribute>
	<dm:listener listener="list2" event="next" action="addValue"/>
      </dmio:attribute>

    </dmio:element>
    
  

The Java code to load the XML and run the example is:

    DatamixerContext context = root.getContext ();

    // read
    context.getElement("element").read ();

    // dump the lists
    System.out.println (context.getValueList ("list0"));
    System.out.println (context.getValueList ("list1"));
    System.out.println (context.getValueList ("list2"));
  

The result is:

    [10, 13, 16]
    [11, 14, 17]
    [12, 15, 18]