Examples of the allowextra option with extra elements for a subfield array
Examples of the allowextra option with extra elements for a subfield array
The following definitions are used in the examples
D employee DS QUALIFIED
D name 10A VARYING
D type 10A
D empInfo2 DS QUALIFIED
D emp LIKEDS(employee)
D DIM(2)
D empInfoAway DS QUALIFIED
D emp LIKEDS(employee)
D DIM(2)
D away 10A DIM(2)
Assume that file emp.xml contains the following lines:
<employees>
<emp><name>Jack</name><type>Normal</type></emp>
<emp><name>Mary</name><type>Manager</type></emp>
<emp><name>Sally</name><type>Normal</type></emp>
</employees>
-
Option allowextra=yes must be specified with data structure empInfo2, since the XML document has three emp XML elements, and the RPG emp array only has two elements.
xml-into empInfo2 %XML('emp.xml' : 'doc=file allowextra=yes path=employees'); // empInfo2.emp(1) .name = 'Jack' .type = 'Normal' // empInfo2.emp(2) .name = 'Mary' .type = 'Manager' -
Option allowextra is not specified for data structure empInfo2. The XML-INTO operation fails with status 00353 because the XML document has too many “emp” elements for the RPG array.
xml-into(e) empInfo2 %XML('emp.xml' : 'doc=file path=employees'); // %error = *on // %status = 353 -
Structure empInfoAway requires two emp elements and two away elements. The XML document contains three emp elements and zero away elements. Option allowextra=yes allowmissing=yes is specified, so the operation will succeed with any number of emp and away XML elements. The extra emp element and missing away elements will be ignored.
xml-into empInfoAway %XML('emp.xml' : 'allowextra=yes ' + 'allowmissing=yes ' + 'path=employees ' + 'doc=file'); // empInfoSite.emp(1) .name = 'Jack' .type = 'Normal' // empInfoSite.emp(2) .name = 'Mary' .type = 'Manager' // empInfoSite.away(1) = ' ' // empInfoSite.away(2) = ' '