The element Element

As shown in the code in "A DTD for Schemas," the simplified DTD declaration for an element element is as follows:

  <!ELEMENT element  ((annotation)?, (complexType | simpleType)?,
                      (unique | key | keyref)*)>
  <!ATTLIST element  type      CDATA  #IMPLIED
                     name      CDATA  #IMPLIED
                     ref       CDATA  #IMPLIED
                     minOccurs  (1 | 0 )  #IMPLIED
                     maxOccurs CDATA  #IMPLIED
                     id        ID     #IMPLIED
                     nullable (true | false ) 'false'
                     default CDATA #IMPLIED
                     fixed CDATA #IMPLIED >

The name attribute is the name of the element. The name attribute must follow all the rules defined for DTD element names. You can define your element using a complexType element, a simpleType element, or a type attribute. The type attribute and either the simpleType element or the complexType element are mutually exclusive. If you are declaring a data type, then one and only one of these must be used for the datatype declaration to be valid.

The type attribute

The type attribute associates either a simple or complex data type with an element. As we've seen, simple data types are either the predefined simple data types or simple data types you define based on these predefined simple data types. Complex data types can be used to associate attributes, elements, or a combination of both to an element. For example, you can declare the simple data type String24 and associate it with the customerName element, as shown here:

  <simpleType name="String24" base="string">
      <maxLength= "24"/ >
      <minLength = "0"/>
  <element name = "customerName" type = "String24"/>

In this case, you have created a data type named String24 that has a length between 0 and 24 characters. This data type is then used in the element declaration, which means that the customerName element will be a string that is between 0 and 24 characters.

The customerName declaration uses document scope, meaning that all elements in the document can see the String24 data type. The type attribute can be used to assign either a complex or a simple data type with document scope to an element.

by BrainBellupdated