Freigeben über


<xdr:ElementType> Element 

Defines an element type for use within the XML-Data Reduced (XDR) schema Schema element.

<ElementType
  content="{empty | textOnly | eltOnly | mixed}" 
  dt:type="datatype" 
  model="{open | closed}" 
  name="idref" 
  order="{one | seq | many}">

Attributes

  • content
    An indicator of whether the content must be empty or can contain text, elements, or both. The following values can be assigned to this attribute. The default value for the content attribute is mixed. When the content attribute is set to mixed, the order attribute requires a many value.

    empty

    The element cannot contain content.

    textOnly

    The element can contain only text, not elements. If the model attribute is set to open, the element can contain text and other unnamed elements.

    eltOnly

    The element can contain only the specified elements. It cannot contain any free text.

    mixed

    The element can contain a mix of named elements and text. The default value is mixed. If the value of the content attribute is mixed, minOccurs and maxOccurs attributes will not trigger a validation error if the number of child elements is outside the specified boundary.

Note

Elements with content="empty" and model="open" are not allowed.

Example

The following example shows use of the content attribute with different values.

<ElementType name="x" content="empty"/>
<ElementType name="x" content="textOnly"/>
<ElementType name="x" content="eltOnly">
  <element type="y"/>
</ElementType>
<ElementType name="x" content="mixed">
  <element type="q"/>
  <element type="r"/>
</ElementType>

Legacy Code Example

The following example shows the content attribute for an equivalent document type definition (DTD).

empty: <!ELEMENT x EMPTY>
textOnly: <!ELEMENT x (#PCDATA)>
eltOnly: <!ELEMENT x y>
mixed: <!ELEMENT x (#PCDATA | q | r)*>
  • dt:type
    The data type of the element. The valid data types are defined in the XDR Schema Data Types Reference.
  • model
    An indicator of whether the content can include only what is defined in the content model. The default is open.

    <ElementType name="x" model="open"/>
    

    When the model is defined as open, the element can include additional elements or attributes not declared explicitly in the content model. These additional tags can come from the same or a different namespace. If they are in the same namespace, there must be a corresponding ElementType or AttributeType definition for them in the schema.

    When the model is defined as closed, the element cannot include elements and mixed content not specified in the content model. The DTD uses a closed model.

  • name
    The name of the element. This attribute is required. If this element type is declared as a valid child of another element type, this name is specified within an element element.

    <ElementType name="x">
    </ElementType>
    

    The DTD equivalent is as follows.

    <!ELEMENT x EMPTY>
    
  • order
    An indicator of how the elements are to appear. This indicator can have the following values.

    one

    Permits only one of a set of elements. For a document to correctly validate when the one attribute is specified, the model attribute for the ElementType must be specified as closed.

    seq

    Requires the elements to appear in the specified sequence.

    many

    Permits the elements to appear (or not appear) in any order. If you specify many for the order attribute, maxOccurs values are no longer relevant during validation.

    The seq value is required to specify valid sequences. For example, it can be used to specify when a particular sequence, such as x1,y1 or x2,y2, is valid but no other possible combinations are valid. The seq value serves the same role as parentheses in a DTD. The default value is seq.

    The following example demonstrates the one setting. The value of the model attribute must be closed when one is specified for the order attribute.

    <ElementType name="z" content="eltOnly" order="one" model="closed">
    <element type="x" minOccurs="1" maxOccurs="1"/>
    <element type="y" minOccurs="1" maxOccurs="1"/>
    </ElementType>
    

    The following example demonstrates the seq setting.

    <ElementType name="x" content="eltOnly" order="one" model="closed">
      <group order="seq" content="eltOnly" model="closed">
        <element type="x1"/>
        <element type="y1"/>
      </group>
      <group order="seq" content="eltOnly" model="closed">
        <element type="x2"/>
        <element type="y2"/>
      </group>
    </ElementType>
    

    The following example demonstrates the many setting.

    <ElementType name="x" content="eltOnly" order="many" model="closed">
      <element type="q"/>
      <element type="r"/>
    </ElementType>
    

    The many setting of the order attribute makes the minOccurs and maxOccurs attributes irrelevant during validation. Rather than using the many setting for the order attribute in conjunction with minOccurs and maxOccurs, use the seq setting instead. For example, consider the following schema, which sets order="seq".

    <?xml version="1.0"?>
    <Schema name="SampleSchema" xmlns="urn:schemas-microsoft-com:xml-data"
        xmlns:dt="urn:schemas-microsoft-com:datatypes">
        <ElementType name="PublisherID" model="closed" dt:type="ID"
          content="textOnly">
        </ElementType>
        <ElementType name="PublisherName" model="closed" dt:type="string"
          content="textOnly">
        </ElementType>
    
        <ElementType name="Publisher" model="closed" content="eltOnly"
          order="many">
          <element type="PublisherID"/>
          <element type="PublisherName"/>
        </ElementType>
    
        <ElementType name="Book" model="closed" content="eltOnly"
          order="seq">
        <element type="Publisher" minOccurs="1" maxOccurs="1"/>
        </ElementType>  
    
    </Schema>
    

If the following XML document is validated against the preceding schema, the validation fails because the number of Publisher elements exceeds the specified maxOccurs value of 1. However, if the order value is set to many, the validation will incorrectly succeed because the maxOccurs="1" setting will be ignored.

<?xml version='1.0'?>
<Book xmlns="x-schema:orderschema.xml" >

<Publisher>
    <PublisherID>P1</PublisherID>
    <PublisherName>GGG</PublisherName>
</Publisher>
<Publisher>
    <PublisherID>P2</PublisherID>
    <PublisherName>North</PublisherName>
</Publisher>

</Book>

Element Information

Number of occurrences

Unlimited

Parent elements

Schema

Child elements

attribute, AttributeType, datatype, description, element, group

Element Properties

TAG Explanation

Name="idref"

ElementType and AttributeType elements must have names.

Model="open"

Elements or mixed content not specified in the content model is permitted in this element. To subclass a particular definition, this setting must be open (when inheritance is implemented in the future).

Model="closed"

Elements or mixed content not specified in the content model is not permitted in this element.

content="empty"

The element may not contain anything.

content="textOnly"

The element may contain only text, not elements. If model="open", the element may still contain text and other unnamed elements.

*

content="mixed"

The element may contain a mixture of named elements and intermingled text. If model="open", the element may still contain text and other unnamed elements. Implies order='many' and maxOccurs="*"!

order='one'

Permits only one of a set of elements.

*

order='seq'

Indicates that the elements must appear in the listed sequence. This is similar to the default for a list of elements, however this is necessary in order to group sequences, as in the example where either x1,y1 or x2,y2 is legal but where no other combinations are. Serves the same role as parentheses in a DTD.

order='many'

The elements may appear (or not appear) in any order.

dt:type=datatype

Specifies that the element should contain an integer. For a list of primitive data types, see the XDR Schema Data Types Reference.

Remarks

The term "element type" refers to the element type of which all elements sharing a name are instances. Element types are declared in schemas; elements occur in documents. Element types are declared with the ElementType element type.

Example

<ElementType name="x">
  <!-- element content declarations go here -->
</ElementType>

See Also

Reference

XDR Schema Data Types Reference