Examples of the path option with non-array variables

The following definitions are used in the examples
D info            DS
D   num                          5P 2

D xmlDoc          S           1000A    VARYING

D qualDs          DS                   QUALIFIED
D   subf                        10A
  1. The path option is used to specify the name for the XML element because the XML name myinfo is different from the RPG name info.
     /free
    
      xmlDoc = '<myinfo><num>123.45</num></myinfo>';
      xml-into info %XML(xmlDoc : 'path=myinfo');
      // num = 123.45
  2. The path option is not specified, but the RPG name info is different from the XML name myinfo. The XML-INTO operation fails with status 00353 because the XML document does not contain the info element.
      xmlDoc = '<myinfo><num>456.1</num></myinfo>';
      xml-into(e) info %XML(xmlDoc');
      // %error = '1'
      // %status = 353
  3. The required XML element is not the outermost element in the XML document, so the path option is used to locate the required XML element.
      xmlDoc = '<data><info><num>-789</num></info></data>';
      xml-into info %XML(xmlDoc : 'path=data/info');
      // num = -789
  4. The target of the XML-INTO operation is a subfield rather than a data structure. The path option specifies the path to the num XML element that matches the num RPG subfield.
      xmlDoc = '<data><info><num>.3</num></info></data>';
      xml-into num %XML(xmlDoc :
                        'path=data/info/num');
      // num = .3
  5. The XML document is in a file, so both the doc option and path option must be specified.
      //
      //    myfile.xml:
      //      <data>
      //       <val>17</val>
      //      </data>
      xml-into num %XML('myfile.xml' : 'doc=file path=data/val');
      // num = 17
  6. A qualified subfield is specified as the target of the XML-INTO operation. The subfield name subf matches the XML name subf, so the path option is not required.
      xmlDoc = '<subf>-987.65</subf>';
      xml-into qualDs.subf %XML(xmlDoc);
      // qualDs.subf = '-987.65'
  7. The XML document has two levels of elements, qualds and subf. The XML document matches the RPG qualds data structure, but the RPG program specifies qualds.subf as the target of the XML operation. The default path is the name of the subfield, so the path option must be specified as path=qualds/subf. It must include the names of all the XML elements in the path to the required XML element, including the XML element containing the data to set the variable.
      xmlDoc = '<qualds><subf>-987.65</subf></qualds>';
      xml-into qualDs.subf %XML(xmlDoc :
                         'path=qualds/subf);
      // qualDs.subf = '-987.65'