Share via


ELEMENT

The ELEMENT statement is used to declare each element used within the document type defined by the DTD. It first declares the element by name, and then specifies what content is allowed for the element.

Syntax

<!ELEMENT  name  content >

Parameters

  • name
    The name of the element. Exact case is required.
  • content
    The allowable content model for the element, which must be one of the following:

    • ANY - Any content is allowed within the element. When used in an element declaration, this keyword permits an open unrestricted content model for the elements and any of its child nodes.

    • EMPTY - The element is not allowed to have content and must remain empty.

    • Declared content rule – For this option, you need to write a content rule and enclose it within a set of parentheses.

      The following table displays the reserved keyword or punctuation symbols that can be used along with names of other elements that are declared within the DTD to construct the element content rule.

      Symbols Description

      #PCDATA

      Allows parsed character data as part of the content of the element.

      name

      The name of an element. This can be the element being defined, or other elements defined by name in the DTD, using additional ELEMENT declarations.

      If there are no other punctuation markers or symbols in the content rule, one and only one occurrence of the named element is allowed and required.

      ()

      Although at least one set of parentheses is required whenever declaring a content model for an element, you can nest additional sets of parentheses as well. This technique can be used to define a more complex content model for an element.

      |

      A vertical bar can be used to separate two named elements. When used, it indicates that either element (i.e. the one before the bar or the one after it) can appear as child elements.

      ,

      The comma can be used to separate two named elements or nested rules. When used, it indicates that the elements/rules must appear in the order specified.

      ?

      The question mark can be used as a suffix/operand. When used, it indicates that the element/rule that precedes it is optional, but if it is used it can occur only once at this point in the XML document structure.

      +

      The plus sign can be used as a suffix/operand. When used, it indicates that the element/rule that precedes it is required, and can occur more than once at this point in the XML document structure.

      *

      The asterisk can be used as a suffix/operand. When used, it indicates that the element/rule that precedes it is optional, and can occur more than once at this point in the XML document structure.

Examples

  • Declares a <test> element that can contain any content:

    <!ELEMENT  test  ANY  >
    
  • Declares an <Image> element that must be empty (i.e. cannot have content):

    <!ELEMENT  Image  EMPTY  >
    
  • Declares a <title> element that can contain character data only (no other markup):

    <!ELEMENT  title  (#PCDATA)  >
    
  • Declares a <fruit> element that contain either an <apple> element or an <orange> element:

    <!ELEMENT  fruit  (apple|orange)  >
    
  • Declares a <book> element that must contain an <author> element followed by a <title> element:

    <!ELEMENT  book  (author,title)  >
    
  • Declares a <memo> element that must contain a <body> element which can be optionally followed by a <postscript> element:

    <!ELEMENT  memo  (body,postscript?)  >
    
  • Declares a <catalog> element that must contain one or more <book> elements:

    <!ELEMENT  catalog  (book+)  >
    
  • Declares a <table> element that can either be empty or contain <rowset> elements:

    <!ELEMENT  table  (rowset*)  >
    

See Also

Concepts

ATTLIST (Attribute List)
ENTITY
NOTATION