Coupon Accepted Successfully!



A DTD allows you to define a valid vocabulary for an XML document. The XML document can then be validated against the DTD. DTDs should be placed on the line immediately following the XML declaration and take the form:


<!DOCTYPE root-element-name [ ]>

Between the square brackets, you can place declarations for the elements, attributes and entities defined by the DTD: this is called internal subset declaration.

Element Declarations

The element declaration begins: <!ELEMENT followed by the element name and a definition of the content (content model). The content model may contain element children, text, a combination of both or it may be empty. For element content, the content can be specified as a sequence or option group or both:

<!ELEMENT order (elem1, elem2, elem3)>

<!ELEMENT order (elem1 | elem2 | elem3)>

<!ELEMENT order (elem1 | (elem2, elem3))>

<!ELEMENT order (elem1, (elem2 | elem3))>

Text content is specified as #PCDATA, and mixed content is specified by combining #PCDATA and element content as choices in the content model. The #PCDATA content must be listed first:

<!ELEMENT order (#PCDATA)>

<!ELEMENT order (#PCDATA | elem1| elem2 | elem3)*>

With mixed content you must also include a ‘cardinality indicator’ of ‘zero or more’ (*) after the closing bracket of the content model. Other cardinality indicators are ‘zero or once’ (?), ‘once or more (+). If no cardinality indicator is given, this indicates ‘once and only once’

The content model can also be specified as ‘empty’ (no content) or ‘any’ (any content from the DTD can appear in any order):


<!ELEMENT comment ANY>

Entity    Declarations

Entity Type :  Description

Built-in         :  There are five built-in entities in XML: &, <, >,’,”. To use these entities, begin with an & character, followed by the entity name (amp, it, gt, apos, quot), and end with a semi-colon

Character      :   To use unicode characters, begin with a ampersand, followed by a hash, the unicode value for the character, and finish with a semicolon. Or you can use the hexidecimal Unicode value by beginning with an ampersand, followed by a hash, an ‘x’, the hexadecimal value and finish with a semicolon. The unicode charts can be found at

General         :   Must be declared previously in the DTD before use. Generally used to specify reusable string and can be declared using internal declaration, texternal system declaration or extemal public declaration:

  • <!ENTITY my-string “Bult with Template Toolkit”>
  • <!ENTITY my-object “filename. txt”>
    To refer to a general entity, simply precede the entity name with a ampersand: & my-string

Parameter     :    Unlike General entities, Parameter entities car be made from DTD declaration, and thus can be used to refer to other DTDs, allowing modular development of DTDs:
<!ENTITY % HTML lat1 PUBLIC”-//W3C//ENTITIES Latin 1 for XHTML//EN” xhtml-lat1.ent”>

To refer to a Parameter entity precede the name with a percent sign

Test Your Skills Now!
Take a Quiz now
Reviewer Name