Section 22.5.  Schema inclusion

Prev don't be afraid of buying books Next

22.5. Schema inclusion

The schema inclusion facility allows a schema definition to treat another schema definition's contents as part of its own. Example 22-12 uses the include element to incorporate declarations from the schema in Example 22-13. The declarations are thenceforth treated as part of the book.xsd schema.

Example 22-12. book.xsd schema definition including declarations from common.xsd
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"         xmlns:myns="http://www.myns.net/myns"    targetNamespace="http://www.myns.net/myns">   <xsd:include schemaLocation="common.xsd"/>   <xsd:element name="book">     <xsd:complexType>       <xsd:sequence>         <xsd:element ref="myns:title"/>         <xsd:element ref="myns:chapter" maxOccurs="unbounded"/>       </xsd:sequence>     </xsd:complexType>   </xsd:element>   <xsd:element name="chapter">     <xsd:complexType>       <xsd:sequence>         <xsd:element ref="myns:title"/>         <xsd:element ref="myns:par" maxOccurs="unbounded"/>       </xsd:sequence>     </xsd:complexType>   </xsd:element> </xsd:schema> 

Example 22-13. common.xsd schema definition
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"         xmlns:myns="http://www.myns.net/myns"    targetNamespace="http://www.myns.net/myns">   <xsd:element name="title" type="xsd:string"/>   <xsd:element name="par" type="xsd:string"/> </xsd:schema> 

In addition to inclusion, XSDL also has support for importing and redefinition of other schemas. Importing is for combining schemas that describe different namespaces. A redefinition allows you to include another schema and override bits and pieces of the included schema. For instance you could redefine the type of an element or attribute that you are including.

Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net