By default, complex types in declare sequences of elements must appear in a conforming document. It turns out that you can also create sequences yourself using the <xsd:sequence> element.
For example, say that I want to let the borrower borrow not just books, but also a magazine. To do that, I can create a new group named booksAndMagazine. A group collects elements together. You can name groups, and you can then include a group in other elements using the <xsd:group> element and referring to the group by name:
<xsd:complexType name="transactionType"> <xsd:element name="Lender" type="address"/> <xsd:element name="Borrower" type="address"/> <xsd:element ref="note" minOccurs="0"/> <xsd:choice> <xsd:element name="books" type="books"/> <xsd:element ref="book"/> <xsd:group ref="booksAndMagazine"/> <xsd:choice> <xsd:attribute name="borrowDate" type="xsd:date"/> </xsd:complexType>
To create the group named booksAndMagazine, I use the <xsd:group> element; to ensure that the elements inside that group appear in a specific sequence, I use the <xsd:sequence> element this way:
<xsd:complexType name="transactionType"> <xsd:element name="Lender" type="address"/> <xsd:element name="Borrower" type="address"/> <xsd:element ref="note" minOccurs="0"/> <xsd:choice> <xsd:element name="books" type="books"/> <xsd:element ref="book"/> <xsd:group ref="booksAndMagazine"/> <xsd:choice> <xsd:attribute name="borrowDate" type="xsd:date"/> </xsd:complexType> <xsd:complexType name="books"> <xsd:element ref="book" minOccurs="0" maxOccurs="10" /> </xsd:complexType> <xsd:group name="booksAndMagazine"> <xsd:sequence> <xsd:element ref="books"/> <xsd:element ref="magazine"/> </xsd:sequence> </xsd:group> <xsd:element name="book"> <xsd:complexType> <xsd:element name="bookTitle" type="xsd:string"/> <xsd:element name="pubDate" type="xsd:date" minOccurs='0'/> <xsd:element name="replacementValue" type="xsd:decimal"/> <xsd:element name="maxDaysOut"> <xsd:simpleType base="xsd:integer"> <xsd:maxExclusive value="14"/> </xsd:simpleType> </xsd:element> <xsd:attribute name="bookID" type="catalogID"/> </xsd:complexType> </xsd:element> <xsd:element name="magazine"> <xsd:complexType> <xsd:element name="magazineTitle" type="xsd:string"/> <xsd:element name="pubDate" type="xsd:date" minOccurs='0'/> <xsd:element name="maxDaysOut"> <xsd:simpleType base="xsd:integer"> <xsd:maxExclusive value="14"/> </xsd:simpleType> </xsd:element> <xsd:attribute name="magazineID" type="catalogID"/> </xsd:complexType> </xsd:element>
18.216.254.96