XML

The attributeGroup Element

As you can see in the simplified DTD for schemas in "," there is nothing equivalent to the DTD parameter entity used for attributes in schemas. Schemas do, however, allow you to create something similar to a parameter entity for attributes by using the attributeGroup element. Attribute groups declared using the attributeGroup element can have either document-level scope or local scope. (The element can be included in the declaration of the schema element or in the declaration of the complexType element.) In the original version of the schema, all attributes were defined without using the attributeGroup element.

The sample DTD we created in Chapter 5 included a parameter entity named attrs. You can define an attribute group named attrs in your schema as follows:

  <schema>
      <attributeGroup name="attrs">
          <attribute name = "id" type = "ID"/>
          <attribute name = "class" type = "string"/>
          <attribute name = "style" type = "string"/>
          <attribute name = "lang" type = "NMTOKEN"/>
          <attribute name = "xml:lang" type = "NMTOKEN"/>
          <attribute name = "dir">
              <simpleType source = "ENUMERATION">
                  <enumeration value = "ltr"/>
                  <enumeration value = "rtl"/>
              </simpleType>
          </attribute>
          <attribute name = "onclick" type = "string"/>
          <attribute name = "ondblclick" type = "string"/>
          <attribute name = "onmousedown" type = "string"/>
          <attribute name = "onmouseup" type = "string"/>
          <attribute name = "onmouseover" type = "string"/>
          <attribute name = "onmousemove" type = "string"/>
          <attribute name = "onmouseout" type = "string"/>
          <attribute name = "onkeypress" type = "string"/>
          <attribute name = "onkeydown" type = "string"/>
          <attribute name = "onkeyup" type = "string"/>
          <attribute name = "href" type = "string"/>
          <attribute name = "name" type = "string"/>
          <attribute name = "target" type = "string"/>
      </attributeGroup>
  
  </schema>

You can use attrs as follows:

  <element name = "option">
      <type content = "textOnly">
          <attributeGroup ref = "attrs"/>
          <attribute name = "selected"/>
          

Thus, you declare the attributeGroup element as a child element of the schema element to create a document scope group of attributes. You can then reference the document scope attributeGroup element in a type element by including an attributeGroup element in the type element with the ref attribute set equal to the name of the document scope group. As you can see, this greatly simplifies the schema.

NOTE
Attribute groups can contain only simple data types.

by BrainBellupdated
Advertisement: