by Thomas Erl
 XML Core Technology
divider
 Inside XML Schemas
 
XSD is a comprehensive data modeling language for XML documents, and the one XML schema specification that has received the broadest industry support across contemporary XML and Web services technologies.
Unlike DTDs, the XML Schema Definition Language is an actual implementation of the XML language; schemas are themselves XML documents. XSD provides the structural and validation-related features offered by the DTD language within an extended feature set consisting of many more variations and options in how to model and establish validation criteria for XML document data.
One of the most important features introduced by the XML Schema specification, is the wide range of support for data types. This greatly refines the quality of XML data representation, and further underscores its role as an enterprise data transport standard. XSD schemas also provide support for namespaces. This enables the schema author to establish logical domains to which some or all parts of a schema can be applied.

The XML Schema document format is very flexible and highly extensible. Each schema definition is capable of containing multiple schema documents. This allows for the creation of modular schemas that can be combined or individually processed.


Each schema can be dynamically extended with supplementary constructs. This allows schemas to adapt to different data representation requirements.



Parts of a schema definition can be redefined (overridden) by other schema definitions. This allows you to create a series of schema classes.
 

return to homepage


SOA: Principles
of Service Design

by Thomas Erl

An in-depth guide dedicated to service engineering with a thorough exploration of the design principles that comprise the service-orientation design paradigm (including a comparison with object-orientation).


Service-Oriented Architecture:
Concepts, Technology, and Design

by Thomas Erl

The first "how-to" guide to building SOA, providing coverage of WS-* specifications, .NET and J2EE platforms, and step-by-step processes for service-oriented analysis and design.
Service-Oriented Architecture:
A Field Guide
to Integrating
XML and Web Services

by Thomas Erl

The best-selling guide to service-oriented integration, providing hundreds of integration strategies and over sixty best practices.

For more information about either book, visit: www.soabooks.com

About SOA Systems

SOA Systems Inc. provides strategic SOA consulting services and offers a comprehensive SOA training program.

For more information see:

•  www.soasystems.com

•  www.soatraining.com



   
   
The XSD schema is defined using the following header statements:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Note the use of the xmlns:xsd attribute, which declares the namespace. This value is carried forward throughout the schema by the use of the xsd: prefix.
Schemas can be fully customized, and developers can create and link schemas to their own namespaces, by using custom prefixes.
<xsd:element name="book">
   <xsd:complexType>
     <xsd:sequence>
XML schema elements have either simple or complex types, depending on whether or not they contain attributes or child elements. Since book is a parent element that will have child elements, it has a complex type. The sequence element acts as a compositor, setting up the sequence of the nested child elements.
       <xsd:element name="title" type="xsd:string"/>
       <xsd:element name="author" type="xsd:string"/>
     </xsd:sequence>
Since neither of the title or author elements have attributes or child elements, they have simple types, namely the built-in type xsd:string. The book element, however, does have an attribute, which is declared separately within the complexType construct.
      <xsd:attribute name="category">
         <xsd:simpleType>
           <xsd:restriction base="xsd:string">
             <xsd:enumeration value="Fiction"/>
             <xsd:enumeration value="Non-Fiction"/>
           </xsd:restriction>
         </xsd:simpleType>
      </xsd:attribute>
Note that the use of this attribute also introduces the schema’s first validation rule. The category attribute is limited to one of two values, through the use of the restriction element. Also, notice the use of the simpleType element – since XML attributes cannot contain further attributes or child elements, they always have simple types.
The declaration of the book element, (along with its nested child elements and its attribute) is completed by closing off the complexType and element constructs.
   </xsd:complexType>
</xsd:element>
Finally, the schema construct itself is closed:
The entire XSD schema definition appears as follows:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="book">
   <xsd:complexType>
     <xsd:sequence>
       <xsd:element name="title" type="xsd:string"/>
       <xsd:element name="author" type="xsd:string"/>
     </xsd:sequence>
     <xsd:attribute name="category">
       <xsd:simpleType>
         <xsd:restriction base="xsd:string">
           <xsd:enumeration value="Fiction"/>
           <xsd:enumeration value="Non-Fiction"/>
         </xsd:restriction>
       </xsd:simpleType>
     </xsd:attribute>
   </xsd:complexType>
</xsd:element>
</xsd:schema>
This schema can now be implemented using an XML document, such as our familiar example:
<?xml version=”1.0”?>
<book xmlns="http://www.xmltc.com"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="book.xsd"
  category=”Fiction”>
   <title>Joy of Integration</title>
   <author>Joe Smith</author>
</book>
The above introduction to XSD schemas has only scratched the surface of this technology’s capabilities. The XML Schema Definition Language provides a number of advanced content modeling features, including:
•  support for a wide variety of data types
•  advanced validation syntax
•  the ability to simulate relational schema models through the use of constraints and keys
•  extensibility via the any element
•  modularization using the include and import elements
•  a form of validation inheritance using the redefine element

   
   
Home   Copyright © 1999-2007 SOA Systems Inc.