The db2-xdb:normalization annotation specifies the normalization of whitespace in the XML data to be inserted or to be substituted for $DECOMP_CONTENT (when used with db2-xdb:expression).
db2-xdb:normalization belongs to the set of decomposition annotations that can be added to an XML schema document to describe the mappings between elements and attributes of XML documents to DB2® base tables. The decomposition process uses the annotated XML schema to determine how elements and attributes of an XML document should be decomposed into DB2 tables.
Attribute of <xs:element> or <xs:attribute>, or attribute of <db2-xdb:rowSetMapping>
<db2-xdb:rowSetMapping db2-xdb:normalization="value">
<db2-xdb:rowSet>value</db2-xdb:rowSet>
…
</db2-xdb:rowSetMapping>
http://www.ibm.com/xmlns/prod/db2/xdb1
Because the db2-xdb:normalization annotation is valid only for certain XML schema to SQL character type mappings, when the annotation is specified for unsupported mappings, it is ignored.
The following example shows how whitespace normalization can be controlled with the db2-xdb:normalization annotation. The annotated schema is presented first.
<xs:element name="author">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"
db2-xdb:rowSet="AUTHORS" db2-xdb:column="FIRSTNAME" />
<xs:element name="lastname" type="xs:string"
db2-xdb:rowSet="AUTHORS" db2-xdb:column="SURNAME"
db2-xdb:normalization="whitespaceStrip" />
<xs:element name="activeStatus" type="xs:boolean"
db2-xdb:rowSet="AUTHORS" db2-xdb:column="ACTIVE"
db2-xdb:normalization="canonical" />
<xs:attribute name="ID" type="xs:integer"
db2-xdb:rowSet="AUTHORS" db2-xdb:column="AUTHID"
db2-xdb:normalization="whitespaceStrip" />
</xs:sequence>
</xs:complexType>
</xs:element>
The <author> element that is being mapped is presented next (notable whitespaces are represented below by the '_' underscore character for the purpose of demonstration), followed by the resulting AUTHORS table after the decomposition has completed.
<author ID="__22">
<firstname>Ann</firstname>
<lastname>__Brown_</lastname>
<activeStatus>1</activeStatus>
</author>
AUTHID | FIRSTNAME | SURNAME | ACTIVE | NUMBOOKS |
---|---|---|---|---|
22 | Ann | __Brown_ | true | NULL |
The "whitespaceStrip" setting causes the leading whitespace from the "ID" attribute to be removed before the value is inserted into the target table. Notice, however, that the leading and trailing whitespace from the <lastname> element is not stripped, even though the "whitespaceStrip" setting was specified. This is because the <lastname> element has an XML schema type of string, which is not an applicable type for db2-xdb:normalization. The <activeStatus> child element of <author> is defined as a boolean type, and the canonical representation of boolean types is either the literal "true" or "false". The "canonical" setting for the <activeStatus> element results in the canonical form of "1", which is "true", being inserted into the ACTIVE column of the AUTHORS table.
If in the XML schema presented above, the "ID" attribute had been annotated with db2-xdb:normalization="original" instead, then the original value from the document, "__22" (where the underscore character represents whitespace), would have been inserted into the AUTHID column.