5.2 Types

A fundamental concept of schema is that of a type. In this section, we discuss named types. You can also use anonymous types, as detailed in Section 5.3.

5.2.1 simpleType

A simpleType is a named type that cannot contain element content and cannot carry attributes. All attributes have a simpleType. Elements that are empty or have only text content are also simpleTypes. The Schema Recommendation provides a large number of predefined simpleTypes, the most general of which is "string." Most of these types have fairly descriptive names, such as "integer," "dateTime," and "anyURI." XML Security uses the "base64Binary" simpleType extensively; it indicates an octet stream encoded in base-64 [RFC 2045]. All of the special attribute types declarable in DTDs, such as ID, NMTOKENS, and IDREF, are also available as simpleTypes.

You can define additional simpleTypes by placing restrictions on existing simpleTypes. Such restrictions can affect various "facets" of the simpleType, such as its range of values, pattern of characters, or limitations on certain enumerated values, as explained in [Schema]. For instance, Example 5-1 defines a type for U.S. Social Security numbers of the form ddd-dd-dddd, where d is a digit.

Example 5-1 Use of a simpleType
 <xs:simpleType name="SSN" >   <xs:restriction base="xs:string>     <xs:pattern value="\d{3}-\d{2}-\d{4}"/>   </xs:restriction> </xs:simpleType> 

5.2.2 complexType

A complexType can contain element content and carry attributes. The content permitted by the complexType itself is approximately modeled by the content of the complexType element. In Example 5-2, any element of type test1 must have a "bar" attribute and contain two children elements, foo1 and foo2, in that order. Also, foo1 can have any text content, foo2 has text content that looks like an integer, and the "bar" attribute must have a value that looks like the SSN type shown in Example 5-1.

Example 5-2 Use of a complexType
 <xs:complexType name='test1'>   <xs:sequence>     <xs:element name='foo1' type='xs:string'/>     <xs:element name='foo2' type='xs:integer'/>   </xs:sequence>   <xs:attribute name='bar' type='SSN'/> </xs:compexType> 

You can use <xs:choice/> instead of <xs:sequence/> to indicate that only one out of a series of possibilities should appear. In addition, you can nest these two mechanisms. All but the outer one may include minOccurs and max Occurs attributes, which default to 1, to permit optionality or multiple occurrences.

To allow mixed text and element content in a complexType, add the


attribute to the xs:complexType start tag.

To indicate that a complexType has only attribute content and not element content, simply omit any list of elements.

Secure XML(c) The New Syntax for Signatures and Encryption
Secure XML: The New Syntax for Signatures and Encryption
ISBN: 0201756056
EAN: 2147483647
Year: 2005
Pages: 186

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