Examples of the path option with array variables

The following definitions are used in the examples
D loc             DS                   DIM(2)
D   city                        20A    VARYING
D   prov                         2A
D arr             S              5I 0  DIM(3)
D xmlDoc          S           1000A    VARYING
  1. The XML document has repeating arr elements that are children of the outermost XML element outer. An RPG array is specified as the target of the XML-INTO operation to receive the data for the repeating XML elements. The path option is not needed because the name of the RPG array arr matches the name of the repeating XML elements arr.
      xmlDoc = '<outer>'
                  + '<arr>3</arr>'
                  + '<arr>4</arr>'
                  + '<arr>-2</arr>'
                  + '</outer> ;
      xml-into arr %XML(xmlDoc);
      // arr(1) = 3
      // arr(2) = 4
      // arr(3) = -2
  2. Assume that myarray.xml contains the following:
      <locations>
        <loc><city>Saskatoon</city><prov>SK</prov></loc>
        <loc><city>Regina</city><prov>SK</prov></loc>
      </locations>

    The target of the XML-INTO operation is an array of data structures. The XML document contains repeated XML elements with the name loc, within a container XML element locations. The name of the RPG data structure array is loc so the path option is not required. The name of the outermost XML element is not considered.

      xml-into loc %XML('myarray.xml' : 'doc=file');
      // loc(1).city = 'Saskatoon'  loc(2).city = 'Regina'
      // loc(1).prov = 'SK'         loc(2).prov = 'SK'
  3. Assume that mydata.xml contains the following:
      <data>
        <where><city>Edmonton</city><prov>AB</prov></where>
        <where><city>Toronto</city><prov>ON</prov></where>
      </data>
    The example is similar to the previous one, but the name of the RPG data structure loc is different from the name of the repeating XML elements where. The path option must be specified as path=data/where with the name of the container XML element data and the name of the repeating XML elements where.
      xmlfile = 'mydata.xml';
      xml-into loc %XML(xmlfile : 'path=data/where doc=file');
      // loc(1).city = 'Edmonton'   loc(2).city = 'Toronto'
      // loc(1).prov = 'AB'         loc(2).prov = 'ON'