Example of the nsprefix option

  1. The following definition is used in the example
    D info            DS                  QUALIFIED
    D   type                        25A   VARYING DIM(2)
    D   ns_type                     10A   VARYING DIM(2)
    D   qty                         10I 0
    D   price                        7P 3
    D   ns_price                    10A   VARYING
    Assume that file info3.xml contains the following
    <abc:info xmlns:abc="http://www.abc.xyz"
              xmlns:def="http://www.def.xyz">
     <abc:type>Chair</abc:type>
     <abc:qty>3</abc:qty>
     <def:type>Modern</def:type>
     <abc:price>79.99</abc:price>
    </abc:info>

    XML-INTO options ns=remove nsprefix=ns_ are specified, so that the RPG programmer can obtain the namespace used for the XML name matching some of the RPG subfields. Option nsprefix=ns_ indicates that subfields beginning with NS_ are candidates for holding the namespace values.

    The XML document has two elements that map to the RPG subfield TYPE: abc:type and def:type.

    The TYPE subfield is defined with DIM(2) because there are two XML elements with the name type, after the namespace is removed. The NS_TYPE subfield is also defined with DIM(2) so that XML-INTO can place the namespace value for each occurrence of an XML name matching the TYPE subfield.

    When XML-INTO handles the XML name abc:type, it will set the TYPE(1) subfield to the value 'Chair' and it will set the NS_TYPE(1) subfield to the value 'abc'.

    When XML-INTO handles the XML name def:type, it will set the TYPE(2) subfield to the value 'Modern' and it will set the NS_TYPE(2) subfield to the value 'def'.

    When XML-INTO handles the XML name abc:qty, it sets the QTY subfield to the value 3. There is no subfield with the name NS_QTY, so the namespace value is not saved in a subfield.

    When XML-INTO handles the XML name abc:price, it will set the PRICE subfield to the value 79.99 and it sets the NS_PRICE subfield to the value 'abc'.

       xml-into info %xml('info3.xml'
                       : 'doc=file ns=remove nsprefix=ns_');
       // info.type(1) = 'Chair'
       // info.ns_type(1) = 'abc'
       // info.type(2) = 'Modern'
       // info.ns_type(2) = 'def'
       // info.qty = 3
       // info.price = 79.99
       // info.ns_price = 'abc'