Annotations of derived complex types for annotated XML schema decomposition
When annotating complex types derived by restriction or extension for decomposition, you need to apply additional mappings.
Derived by restriction
Complex types that are derived by restriction require that the common elements and attributes from the base type be repeated in the definition of the derived type. Decomposition annotations that are present in the base type, therefore, must also be included in the derived type.
Derived by extension
In the definition of complex types derived by extension, only the elements and attributes that are in addition to the base type are specified. If the decomposition mappings for the derived type differ from the mappings of the base type, then decomposition annotations must be added to the base type to clearly differentiate the mappings of the base from the derived types.
outOfPrintBookType
,
can be mapped to a different table than its base type, bookType
.
Notice how the db2-xdb:locationPath annotation
is specified in the bookType
base type to clearly
differentiate which mappings apply to the base type, and which apply
to the derived type. The <lastPublished> and <publisher>
elements of the derived type outOfPrintType
do not
require the db2-xdb:locationPath annotation
in this example, as these elements are involved only in a single mapping.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:db2-xdb="http://www.ibm.com/xmlns/prod/db2/xdb1">
<xs:annotation>
<xs:appinfo>
<db2-xdb:table>
<db2-xdb:name>BOOKS</db2-xdb:name>
<db2-xdb:rowSet>inPrintRowSet</db2-xdb:rowSet>
</db2-xdb:table>
<db2-xdb:table>
<db2-xdb:name>OUTOFPRINT</db2-xdb:name>
<db2-xdb:rowSet>outOfPrintRowSet</db2-xdb:rowSet>
</db2-xdb:table>
</xs:appinfo>
</xs:annotation>
<xs:element name="books">
<xs:complexType>
<xs:choice>
<xs:element name="book" type="bookType"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="outOfPrintBook" type="outOfPrintBookType"
minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="bookType">
<xs:sequence>
<xs:element name="authorID" type="xs:integer"/>
<xs:element name="chapter" type="chapterType" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="title" type="xs:string"
db2-xdb:locationPath="/books/book/@title"
db2-xdb:rowSet="inPrintRowSet" db2-xdb:column="TITLE">
<xs:annotation>
<xs:appinfo>
<db2-xdb:rowSetMapping db2-xdb:locationPath="/books/outOfPrintBook/@title">
<db2-xdb:rowSet>outOfPrintRowSet</db2-xdb:rowSet>
<db2-xdb:column>TITLE</db2-xdb:column>
</db2-xdb:rowSetMapping>
</xs:appinfo>
</xs:annotation>
</xs:attribute>
<xs:attribute name="isbn" type="xs:string"
db2-xdb:locationPath="/books/book/@isbn"
db2-xdb:rowSet="inPrintRowSet" db2-xdb:column="ISBN">
<xs:annotation>
<xs:appinfo>
<db2-xdb:rowSetMapping db2-xdb:locationPath="/books/outOfPrintBook/@isbn">
<db2-xdb:rowSet>outOfPrintRowSet</db2-xdb:rowSet>
<db2-xdb:column>ISBN</db2-xdb:column>
</db2-xdb:rowSetMapping>
</xs:appinfo>
</xs:annotation>
</xs:attribute>
</xs:complexType>
<xs:complexType name="outOfPrintBookType">
<xs:complexContent>
<xs:extension base="bookType">
<xs:sequence>
<xs:element name="lastPublished" type="xs:date"
db2-xdb:rowSet="outOfPrintRowSet" db2-xdb:column="LASTPUBDATE"/>
<xs:element name="publisher" type="xs:string"
db2-xdb:rowSet="outOfPrintRowSet" db2-xdb:column="PUBLISHER"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="paragraphType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:complexType name="chapterType">
<xs:sequence>
<xs:element name="paragraph" type="paragraphType" maxOccurs="unbounded"
db2-xdb:locationPath="/books/book/chapter/paragraph"
db2-xdb:rowSet="inPrintRowSet" db2-xdb:column="CONTENT">
<xs:annotation>
<xs:appinfo>
<db2-xdb:rowSetMapping
db2-xdb:locationPath="/books/outOfPrintBook/chapter/paragraph">
<db2-xdb:rowSet>outOfPrintBook</db2-xdb:rowSet>
<db2-xdb:column>CONTENT</db2-xdb:column>
</db2-xdb:rowSetMapping>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="number" type="xs:integer"/>
<xs:attribute name="title" type="xs:string"/>
</xs:complexType>
</xs:schema>
The annotations indicate that values
from the <book> element will be decomposed into the BOOKS table,
while values from the <outOfPrintBook> element will be decomposed
into the OUTOFPRINT table.<books>
<book isbn="1-11-111111-1" title="My First XML Book">
<authorID>22</authorID>
<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>
</book>
<outOfPrintBook isbn="7-77-777777-7" title="Early XML Book">
<authorID>41</authorID>
<chapter number="1" title="Introductory XML">
<paragraph>Early XML...</paragraph>
</chapter>
<chapter number="2" title="What is XML">
<paragraph>XML is an emerging technology...</paragraph>
</chapter>
<lastPublished>2000-01-31</lastPublished>
<publisher>Early Publishers Group</publisher>
</outOfPrintBook>
</books>
The following tables result from decomposing
the document that this element belongs to, using the preceding annotated
schema:
ISBN | TITLE | CONTENT |
---|---|---|
1-11-111111-1 | My First XML Book | XML is fun... |
1-11-111111-1 | My First XML Book | XML can be used with... |
ISBN | TITLE | CONTENT | LASTPUBDATE | PUBLISHER |
---|---|---|---|---|
7-77-777777-7 | Early XML Book | Early XML... | 2000-01-31 | Early Publishers Group |
7-77-777777-7 | Early XML Book | XML is an emerging technology... | 2000-01-31 | Early Publishers Group |