db2-xdb:column decomposition annotation
The db2-xdb:column annotation specifies a column name of the table to which an XML element or attribute has been mapped.
Annotation type
Attribute of <xs:element> or <xs:attribute>, or child element of <db2-xdb:rowSetMapping>
How to specify
db2-xdb:column is specified in any of the following ways (where value represents a valid value for the annotation):
- <xs:element db2-xdb:rowSet="value" db2-xdb:column="value" />
- <xs:attribute db2-xdb:rowSet="value" db2-xdb:column="value" />
<db2-xdb:rowSetMapping>
<db2-xdb:rowSet>value</db2-xdb:rowSet>
<db2-xdb:column>value</db2-xdb:column>
…
</db2-xdb:rowSetMapping>
Namespace
http://www.ibm.com/xmlns/prod/db2/xdb1
Valid values
Any base table column name.
Details
- Undelimited column names are case-insensitive.
- When special characters, such as double quotation marks ("), ampersands (&), or less-than signs (<) are part of SQL identifiers, those special characters need to be replaced by their equivalent XML notations. For example, replace " with ", & with &, and < with <.
- db2-xdb:column is an optional child element of db2-xdb:rowSetMapping if the db2-xdb:locationPath annotation is present.
Example
The following example shows how content from the <book> element can be inserted into columns of a table called BOOKCONTENTS, using the db2-xdb:column annotation. A section of the annotated schema is presented first.
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="authorID" type="xs:integer" />
<xs:element name="chapter" type="chapterType" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"
db2-xdb:rowSet="BOOKCONTENTS" db2-xdb:column="ISBN" />
<xs:attribute name="title" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:complexType name="chapterType">
<xs:sequence>
<xs:element name="paragraph" type="paragraphType" maxOccurs="unbounded"
db2-xdb:rowSet="BOOKCONTENTS"
db2-xdb:column="CHPTCONTENT" />
</xs:sequence>
<xs:attribute name="number" type="xs:integer"
db2-xdb:rowSet="BOOKCONTENTS"
db2-xdb:column="CHPTNUM" />
<xs:attribute name="title" type="xs:string"
db2-xdb:rowSet="BOOKCONTENTS"
db2-xdb:column="CHPTTITLE" />
</xs:complexType>
<xs:simpleType name="paragraphType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
The <book> element that is being mapped is presented next, followed by the resulting BOOKCONTENTS table after the decomposition has completed.
<book isbn="1-11-111111-1" title="My First XML Book">
<authorID>22</authorID>
<!-- this book does not have a preface -->
<chapter number="1" title="Introduction to XML">
<paragraph>XML is fun...</paragraph>
...
</chapter>
<chapter number="2" title="XML and Databases">
<paragraph>XML can be used with...</paragraph>
</chapter>
...
<chapter number="10" title="Further Reading">
<paragraph>Recommended tutorials...</paragraph>
</chapter>
</book>
| ISBN | CHPTNUM | CHPTTITLE | CHPTCONTENT |
|---|---|---|---|
| 1-11-111111-1 | 1 | Introduction to XML | XML is fun... |
| 1-11-111111-1 | 2 | XML and Databases | XML can be used with... |
| … | … | … | … |
| 1-11-111111-1 | 10 | Further Reading | Recommended tutorials... |
