Examples of the ns option

  1. Option ns=remove is used.
    The following definition is used in the example
    D info            DS                  QUALIFIED
    D   type                        25A   VARYING
    D   qty                         10I 0
    D   price                        7P 3
    Assume that file info1.xml contains the following
    <abc:info xmlns:abc="http://www.abc.xyz">
     <abc:type>Chair</abc:type>
     <abc:qty>3</abc:qty>
     <abc:price>79.99</abc:price>
    </abc:info>

    The names in the XML document, such as abc:type, cannot be used for RPG subfield names.

    Option ns=remove specifies that the namespace (abc) and colon should be removed from the XML name before the XML-INTO operation searches for a matching subfield or for a name specified in the path option.

    The XML name abc:type matches the RPG subfield TYPE after the namespace abc: is removed.

       xml-into info %xml('info1.xml'
                       : 'doc=file ns=remove');
       // info.type = 'Chair'
       // info.qty = 3
       // info.price = 79.99
  2. Option ns=merge is used.
    The following definition is used in the example
    D info            DS                  QUALIFIED
    D   abc_type                    25A   VARYING
    D   def_type                    25A   VARYING
    D   abc_qty                     10I 0
    D   abc_price                    7P 3
    Assume that file info2.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>

    The XML document contains name abc:type, with namespace abc.

    The XML document also contains name def:type, with namespace def. Option namespace=remove cannot be used in this case, because there would be two different XML elements whose names would match an RPG subfield TYPE.

    Option ns=merge is specified, indicating that the namespace (abc) should be merged with the remainder of the XML name, with an underscore separating the two parts of the name, before the XML-INTO operation searches for a matching subfield.

    The name abc_type matches the RPG subfield ABC_TYPE after the namespace abc is merged with type. The name def_type matches the RPG subfield DEF_TYPE after the two parts of the XML name are merged.

    The data structure name info does not match the merged XML name abc_info, so the path option must be specified. The merged name abc_info is used in the path option.

    See namespace prefix option for another way to handle this type of XML document.

       xml-into info %xml('info2.xml'
                       : 'doc=file ns=merge path=abc_info');
       // info.abc_type = 'Chair'
       // info.def_type = 'Modern'
       // info.abc_qty = 3
       // info.abc_price = 79.99