Custom Datatypes

Summary

XML Schema provides a comprehensive and flexible means of describing the structure as well as the type of data that should appear within an instance document. It is superior to the DTD schema language first introduced with XML 1.0.

XML Schema provides a standard type system. The type system is used to define a platform-independent way of describing the type of data that can be contained within an element or attribute. The type system also provides a set of built-in types that specify the data that can be contained by instances of types such as string, int, and float. Because SOAP is an XML-based protocol, messages can be created and consumed regardless of the hardware, operating system, or XML processing software used.

The type system is also extensible. XML Schema provides the means to define new simple types and complex types. A simple type cannot contain any child elements. Complex types provide a logical way to group related elements and attributes.

A custom type always inherits from another custom type or a built-in type. Simple types can be derived by restriction using a rich syntax for defining additional constraints. They can also be derived by list and by union.

Complex types can be derived by restriction or by extension. They can also contain attributes only (simple content) or attributes and elements (complex content). These attributes and elements can be locally defined or can be references of globally defined entities. If the entities within a complex type are locally defined, they should be associated with the namespace by having their form attribute set to qualified. This makes it easier to author instance documents that reference a default namespace.

XML Schema enables polymorphic behavior by allowing elements to contain instances of derived types to appear within the document. XML Schema also allows elements to be substituted with elements of a compatible type via substitution groups. In order to facilitate polymorphic behavior, instances of derived types must be able to be substituted in place of an instance of its base type.

XML Schema also provides mechanisms for restricting inheritance and polymorphic behavior. Complex type definitions can restrict how the type can be inherited by setting the final attribute. Element definitions can also restrict the type of substitutions that are allowed by setting the block attribute.

A schema document can contain element, attribute, and type definitions. These definitions can be scoped within a particular namespace by setting the targetNamespace attribute within the schema element. The schema can then be referenced by its namespace within an instance document. You can reference a namespace by adding the xmlns attribute to an element within the document. The reference will be scoped to the element that contains the xmlns attribute and any elements or attributes contained within the element.

A reference to a schema namespace can be assigned a moniker. Any entities referenced within the schema must then be prefixed by the moniker. By convention, the XML Schema namespace is assigned the xsd moniker and the XML Schema Instance namespace is assigned the xsi moniker. Also, if the schema contains references to its own definitions, a reference to its own namespace is usually assigned the tns moniker.

A reference to a namespace that is not assigned a moniker is used to define the default namespace. Attributes and elements that are not fully qualified with a prefix that is within the scope of the default namespace declaration are qualified with respect to the default namespace.

XML Schema provides a means of creating a schema that is composed of more than one schema document. The include element is used to include other schema definitions into its namespace. Schemas that do not define a namespace can be included into any schema. If the included schema defines a namespace, it must match the target namespace of the schema that includes it.

XML Schema is the preferred way of describing the schema of messages exchanged between the client and the server. It provides a robust and flexible way to describe the structure and the type of data that can appear within an instance document. As you will see in later chapters, the .NET platform provides a rich framework for creating and consuming XML Schema schemas for Web services.



Building XML Web Services for the Microsoft  .NET Platform
Building XML Web Services for the Microsoft .NET Platform
ISBN: 0735614067
EAN: 2147483647
Year: 2002
Pages: 94
Authors: Scott Short

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