db2-xdb:rowSet decomposition annotation
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.
Annotation type
Attribute of <xs:element> or <xs:attribute>, or child element of <db2-xdb:rowSetMapping> or <db2-xdb:order>
How to specify
<xs:element db2-xdb:rowSet="value" />
<xs:attribute db2-xdb:rowSet="value" />
<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>
Namespace
http://www.ibm.com/xmlns/prod/db2/xdb1
Valid values
Any identifier that adheres to the rules for SQL identifiers. Refer to the identifiers documentation for more information.
Details
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.
- If the value of db2-xdb:rowSet does not match any of the <db2-xdb:rowSet> children elements of the <db2-xdb:table> global annotation, then the name of the target table is the value specified by this annotation, qualified by an SQL schema defined by the <db2-xdb:defaultSQLSchema> global annotation. This usage of db2-xdb:rowSet is for the case in which, for a particular table, there is only one set of elements or attributes that maps to the table.
- If the value of db2-xdb:rowSet matches a <db2-xdb:rowSet> child element of the <db2-xdb:table> global annotation, then the name of the target table is the table named in the <db2-xdb:name> child of <db2-xdb:table>. This usage of db2-xdb:rowSet is for the more complex case in which, for a particular table, there are multiple (possibly overlapping) sets of elements or attributes that map to that table.
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).
Example
The two ways of using db2-xdb:rowSet listed previously, are demonstrated next.
Single set of elements or attributes mapped to a table
<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... |
Multiple sets of elements or attributes mapped to the same table
<!-- 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: - /book/@isbn, /book/@authorID, /book/title
- /textbook/isbn, /textbook/primaryauthorID, /textbook/title
ISBN | TITLE | AUTHORID |
---|---|---|
1-11-111111-1 | My First XML Book | 22 |
0-11-011111-0 | Programming with XML | 435 |