The db2-xdb:rowSet annotation specifies an XML element or attribute mapping to a target base table.
db2-xdb:rowSet 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 child element of <db2-xdb:rowSetMapping> or <db2-xdb:order>
<db2-xdb:rowSetMapping>
<db2-xdb:rowSet>value</db2-xdb:rowSet>
…
</db2-xdb:rowSetMapping>
<db2-xdb:order>
<db2-xdb:rowSet>value</db2-xdb:rowSet>
…
</db2-xdb:order>
http://www.ibm.com/xmlns/prod/db2/xdb1
Any identifier that adheres to the rules for SQL identifiers. Refer to the identifiers documentation for more information.
The db2-xdb:rowSet annotation maps an XML element or attribute to a target base table. This annotation can either identify a table name directly, or identify a rowSet name in more complex mappings, where the rowSet is then associated with a table name through the db2-xdb:table annotation. In simple mappings, this annotation specifies the name of the table the value is to be decomposed into. In more complex mappings, where multiple rowSets (each with a distinct name) map to the same table, then this annotation names the rowSet, rather than the table name.
When the db2-xdb:rowSet annotation is used, either the db2-xdb:column annotation or the db2-xdb:condition annotation must be specified. The combination of db2-xdb:rowSet and db2-xdb:column describe the table and column to which this element or attribute will be decomposed into. The combination of db2-xdb:rowSet and db2-xdb:condition specifies the condition that must be true for any rows of that rowSet to be inserted into the table (referred to either directly, or indirectly through the <db2-xdb:table> annotation).
The two ways of using db2-xdb:rowSet listed above, are demonstrated next.
<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>
Consider the following element from
an XML document: <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>
The BOOKCONTENTS table is then populated as follows:
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... |
<!-- global annotation -->
<xs:annotation>
<xs:appinfo>
<db2-xdb:table>
<db2-xdb:name>ALLBOOKS</db2-xdb:name>
<db2-xdb:rowSet>book</db2-xdb:rowSet>
<db2-xdb:rowSet>textbook</db2-xdb:rowSet>
</db2-xdb:table>
</xs:appinfo>
</xs:annotation>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="authorID" type="xs:integer"
db2-xdb:rowSet="book" db2-xdb:column="AUTHORID" />
<xs:element name="chapter" type="chapterType" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"
db2-xdb:rowSet="book" db2-xdb:column="ISBN" />
<xs:attribute name="title" type="xs:string"
db2-xdb:rowSet="book" db2-xdb:column="TITLE" />
</xs:complexType>
</xs:element>
<xs:element name="textbook">
<xs:complexType>
<xs:sequence>
<xs:element name="isbn" type="xs:string"
db2-xdb:rowSet="textbook" db2-xdb:column="ISBN" />
<xs:element name="title" type="xs:string"
db2-xdb:rowSet="textbook" db2-xdb:column="TITLE" />
<xs:element name="primaryauthorID" type="xs:integer"
db2-xdb:rowSet="textbook" db2-xdb:column="AUTHORID" />
<xs:element name="coauthorID" type="xs:integer"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="subject" type="xs:string" />
<xs:element name="edition" type="xs:integer" />
<xs:element name="chapter" type="chapterType" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="chapterType">
<xs:sequence>
<xs:element name="paragraph" type="paragraphType" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="number" type="xs:integer" />
<xs:attribute name="title" type="xs:string" />
</xs:complexType>
<xs:simpleType name="paragraphType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
Consider the following elements from an
XML document: <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>
<textbook>
<isbn>0-11-011111-0</isbn>
<title>Programming with XML</title>
<primaryauthorID>435</primaryauthorID>
<subject>Programming</subject>
<edition>4</edition>
<chapter number="1" title="Programming Basics">
<paragraph>Before you being programming...</paragraph>
</chapter>
<chapter number="2" title="Writing a Program">
<paragraph>Now that you have learned the basics...</paragraph>
</chapter>
...
<chapter number="10" title="Advanced techniques">
<paragraph>You can apply advanced techniques...</paragraph>
</chapter>
</textbook>
In this example, there are two sets of elements
or attributes that map to the table ALLBOOKS: ISBN | TITLE | AUTHORID |
---|---|---|
1-11-111111-1 | My First XML Book | 22 |
0-11-011111-0 | Programming with XML | 435 |