test

Page 76

The XML Schema type system is highly extensible. It provides a mechanism for defining new datatypes that inherit from either built-in datatypes or custom datatypes. Datatypes fall into two categories, simple types and complex types. Simple types cannot contain subelements or attributes; custom types can.

Simple Types Simple types are datatypes that can be used to describe the type of data contained within an element or an attribute. Instances of simple types cannot contain attributes or other elements. Examples of simple types include int, long, string, and dateTime. A simple type can also define an enumeration or a union. A simple type definition always derives from another simple type. The three types of derivations allowed by XML Schema are by restriction, by list, and by union. A simple type derived from its base type by restriction can define additional restrictions imposed on the values that instances of the simple type can contain. Therefore, instances of a simple type derived by restriction can contain only a subset of the values that can be contained by its base type. For example, the built-in double type is a restricted version of the decimal type. Instances of the decimal type are unbounded, and instances of the double type are restricted to values that meet the IEEE single-precision 64-bit floating type. Following are a couple of simple type definitions that derive by restriction. <?xml version=‘1.0’?> <schema xmlns="http://www.w3.org/2001/XMLSchema.xsd">

<simpleType name="MyInt"> <restriction base="int"/> </simpleType> <simpleType name="GenericProductId"> <restriction base="string"> <minLength value="1"/> <maxLength value="20"/> </restriction> </simpleType> <simpleType name="Percent"> <restriction base="integer"> <minInclusive value="0"/> <maxInclusive value="100"/> </restriction> </simpleType>

</schema>

76


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.