Rational Developer for System z

Support for the nillable attribute

This topic describes the support for the nillable attribute in the COBOL Compiled XML Conversion process.

The nillable attribute can be defined on an xsd:element within an XML schema. It specifies that the xsi:nil attribute is valid for the element. If an XML schema has defined the nillable attribute as true, it is mapped as a required attribute and is included in the document, however, its values are nullified. Depending on the circumstances, the XML conversion process behaves differently when nillable elements are mapped.

The XML2LS (inbound) converter will move all LOW-VALUES to a COBOL field if the following conditions are met:
  1. The XSD element that is mapped to the COBOL field has nillable="true".
  2. The XSD element is mapped to a COBOL field of type PIC X, G, or N.
  3. The XML element specifies xsi:nil="true" and has a content length of 0 (no character content) at execution time.
The LS2XML (outbound) converter will generate the xsi:nil="true" attribute(*2) on an XML element if the following conditions are met:
  1. The XSD element to which the COBOL field is mapped specifies nillable="true".
  2. The COBOL field to which the XSD element is mapped is of type PIC X, G, or N.
  3. The COBOL field contains all LOW-VALUES at execution time.
In Figure 1, when the COPY and XSD files are imported and the COBOL field ELE-1 is mapped to the XSD item ele_1, the following results will be achieved:
Figure 1. xsd:nillable Example
COPY:
01 STRUCT-1.
	05 ATTR-1 PIC X(5).
	05 ELE-1 PIC X(10).

XSD:
<?xml version="1.0" encoding="UTF-8" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:p1="http://www.example.com"
targetNamespace="http://www.example.com"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">

	<xs:element name="ele1_detail">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="ele_1" type="p1:ele_1" nillable="true"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>

	<xs:complexType name="ele_1">
		<xs:simpleContent>
			<xs:extension base="xs:string">
				<xs:attribute name="attr-1">
					<xs:simpleType>
						<xs:restriction base="xs:string">
						</xs:restriction>
					</xs:simpleType>
				</xs:attribute>
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>

</xs:schema>

Feedback