Section 22.2.  Elements and types

Prev don't be afraid of buying books Next

22.2. Elements and types

Notice the four element elements[2] in Example 22-2: poem, title, verse and picture. They declare the properties of a class of elements:

[2] Yes, element elements.

  1. the element-type name;

  2. the data structure of the content; and

  3. attributes provided for the class, including attribute types and default values.

Example 22-2. Poem schema definition in XSDL
 <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"         xmlns:poem="http://www.poetry.net/poetns"    targetNamespace="http://www.poetry.net/poetns">   <xsd:element name="poem">     <xsd:complexType>       <xsd:sequence>         <xsd:element ref="poem:title"/>         <xsd:element ref="poem:picture"/>         <xsd:element ref="poem:verse" maxOccurs="unbounded"/>       </xsd:sequence>       <xsd:attribute name="publisher" type="xsd:string"/>       <xsd:attribute name="pubyear" type="xsd:NMTOKEN"/>     </xsd:complexType>    </xsd:element>   <xsd:element name="title" type="xsd:string"/>   <xsd:element name="verse" type="xsd:string"/>   <xsd:element name="picture">     <xsd:complexType>       <xsd:attribute name="href" use="required" type="xsd:anyURI"/>     </xsd:complexType>   </xsd:element> </xsd:schema> 

In XSDL, a complexType element can define and name a data structure and attributes independently of declaring an element type. There is also a simpleType element, but it can define and name only the simplest data structures:various forms of character strings, such as datatypes.

The unqualified word type in XSDL is reserved for just these two types: complex types and simple types.[3]

[3] In fact the XSDL spec barely mentions any other types (element, attribute, data, etc.), perhaps to avoid confusion with the unqualified use of "type".

An element element, then, declares the element-type name and data structure type of a class of elements. The type could be defined within the content of the element element, as in the case of poem in Example 22-2, in which case the type itself is not named.

Alternatively, if the type was defined and named elsewhere, the declaration could use a type attribute, as shown for the title element. As the xsd prefix in the attribute value suggests, the string type is not actually defined within this schema. XSDL automatically provides named simple type definitions for all of the built-in datatypes. Those names are in the XML Schema namespace.

The two methods of declaring data structure types for elements are equivalent, and are equally applicable to complex and simple types. That includes user-derived datatypes, which, as we saw in 21.2, "Defining user-derived datatypes", on page 451, are actually simple types.

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