One of the nicer features of schema language is the ability to create a new complex type by extending an existing one. The most frequent usage involves taking an existing sequence of Elements and adding a new one at the end. The example below defines RowType, followed by an extension where we add a new column for birth date. You can find the complete schema in SimpleCSV5.xsd.
<xs:complexType name="RowType"> <xs:annotation> <xs:documentation>Here we give a named type to our Row Element, instead of defining it anonymously in-line. </xs:documentation> </xs:annotation> <xs:sequence> <xs:element name="Column01" type="ColumnType" minOccurs="0"/> <xs:element name="Column02" type="ColumnType" minOccurs="0"/> <xs:element name="Column03" type="ColumnType" minOccurs="0"/> <xs:element name="Column04" type="ColumnType" minOccurs="0"/> <xs:element name="Column05" type="ColumnType" minOccurs="0"/> <xs:element name="Column06" type="ColumnType" minOccurs="0"/> <xs:element name="Column07" type="ColumnType" minOccurs="0"/> <xs:element name="Column08" type="ColumnType" minOccurs="0"/> <xs:element name="Column09" type="ColumnType" minOccurs="0"/> <xs:element name="Column10" type="ColumnType" minOccurs="0"/> </xs:sequence> </xs:complexType> <xs:complexType name="RowWithBirthDateType"> <xs:annotation> <xs:documentation>We extend RowType with a column for the birth date </xs:documentation> </xs:annotation> <xs:complexContent> <xs:extension base="RowType"> <xs:sequence> <xs:element name="Column11" type="xs:date" minOccurs="0"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> |
People most commonly use this approach when creating their schemas after performing object-oriented analysis. Deriving complex types by adding Elements is very similar to extending base classes into subclasses with additional properties or methods.