The ElementType Element

The ElementType element is used to define an element type. The ElementType element can have the following child elements: attribute, AttributeType, datatype, description, element, and group. The AttributeType element will create local definitions for the attribute element, the attribute element will be used to define attributes associated with the element, and the element element will be used to define child elements of the element. The datatype element can define an element as being any of the data types listed in the table in the section "The datatype Element."

You can also declare an element as a certain type by using the dt:type attribute as one of the attributes of the ElementType element. In addition to this attribute, the ElementType element also has the model, order, content, and name attributes. The model attribute is used to indicate whether an element can contain content defined only in the content model or can contain content not specified in the content model. A content model is a pattern that you set up to declare what child element types are allowed inside an element and the order of those child elements. If the model attribute is set to open, the default value, the element can contain content that is not specified in the content model. In this case, this attribute is similar to the any type in the W3C standard. If the model attribute is set to closed, the element can contain only content that is defined in the content model.

The order attribute functions the same as its counterpart in the group element. The content attribute can be empty when there is no content, textOnly when the content is only text, eltOnly when the content is only elements, and mixed when the content is a mixture of elements and text. The name attribute defines the name of the element.

If the model attribute is open and the content attribute is textOnly, the content can be both text and unnamed elements.

An example of the ElementType element is shown here:

  <Schema name="NorthwindSchema"
     <AttributeType name="colors"
        dt:type="enumeration" dt:values="red green"/>
     <ElementType name="3Dimage" content="eltOnly" model="closed">
        <attribute type ="colors"/>
        <AttributeType name="width" dt:type="int"/>
        <attribute type = "width"/>
        <group order="seq">
           <element type="x"/>
           <element type="y"/>
           <element type="z"/>

This schema declares a document scope AttributeType element named colors that is defined as an attribute in the 3Dimage element by using the attribute element. A local declaration of an AttributeType element named width is also defined as an attribute in the 3Dimage element by using the attribute element. This pairing of a local AttributeType element followed by an attribute element that uses the AttributeType element as an attribute is the most common way to use these elements. The schema also uses a group element to sequentially group elements.

The following example demonstrates a valid use of this schema:

  <3Dimage color="blue" width="5">

If you change the value of the order attribute in the group element to one in the schema, this example would be invalid; but the following example is valid with the changed schema:

  <3Dimage color="blue" width="5">

You can also declare an ElementType element as a data type. The following declaration creates an integer element named quantity:

  <ElementType name= "quantity" dt:type="int"/>

This element could also be declared as shown here:

  <ElementType name= "quantity" >
     <datatype dt:type="int"/>