DTD Example

The DTD has no header, it is just a set of entity lists, element declarations and attribute declarations. Listed below is an example DTD with some text from the HTML Transitional DTD but modified to provide a simpler example that is complete.

<!ENTITY % HTML.Version "-//W3C//DTD HTML 4.01 Transitional//EN">

<!ENTITY % Script "CDATA" -- script expression -->

<!ENTITY % URI "CDATA" -- a Uniform Resource Identifier, see [URI] -->

<!ENTITY % StyleSheet "CDATA" -- style sheet data -->

<!ENTITY % heading "H1|H2|H3|H4|H5|H6">

<!ENTITY % list "UL | OL">

<!ENTITY % coreattrs
 "id ID #IMPLIED -- document-wide unique id --
 class CDATA #IMPLIED -- space-separated list of classes --
 style %StyleSheet; #IMPLIED -- associated style info --
 title %Text; #IMPLIED -- advisory title --"
 >

<!ENTITY % events
 "onclick %Script; #IMPLIED -- a pointer button was clicked --
 ondblclick %Script; #IMPLIED -- a pointer button was double clicked--
 onmousedown %Script; #IMPLIED -- a pointer button was pressed down --
 onmouseup %Script; #IMPLIED -- a pointer button was released --
 onmouseover %Script; #IMPLIED -- a pointer was moved onto --
 onmousemove %Script; #IMPLIED -- a pointer was moved within --
 onmouseout %Script; #IMPLIED -- a pointer was moved away --
 onkeypress %Script; #IMPLIED -- a key was pressed and released --
 onkeydown %Script; #IMPLIED -- a key was pressed down --
 onkeyup %Script; #IMPLIED -- a key was released --"
 >

<!ENTITY % attrs "%coreattrs; %events;">

<!ENTITY % align "align (left|center|right|justify) #IMPLIED">

<ENTITY % phrase
 "EM | STRONG | DFN | CODE | SAMP
 | KBD | VAR | CITE | ABBR | ACRONYM" >

<!ENTITY % fontstyle
 "TT | I | B | U | S | STRIKE | BIG | SMALL">

<!ENTITY % inline
 "#PCDATA | %phrase; | %fontstyle;">

<ENTITY % block
 "P | %heading; | %list; | HR">

<!ENTITY % flow "%block; | %inline;">

<ELEMENT BODY O O (%flow;)* -- document body -->

<ATTLIST BODY %attrs; -- %coreattrs, %i18n, %events --
 onload %Script; #IMPLIED -- the document has been loaded --
 onunload %Script; #IMPLIED -- the document has been removed --
 background %URI; #IMPLIED -- texture tile for document background --
 >

<!ELEMENT (%fontstyle; | %phrase;) - - (%inline;)*>
<!ATTLIST (%fontstyle; | %phrase;)
 %attrs; -- %coreattrs, %events --
 >

<!ELEMENT (%heading;) - - (%inline;)* -- heading -->
>!ATTLIST (%heading;)
 %attrs; -- %coreattrs, %i18n, %events -- 
 %align; -- align, text alignment -- >

<!ENTITY % Length "CDATA" -- nn for pixels or nn% for percentage length -->

<!ENTITY % Pixels "CDATA" -- integer representing length in pixels -->

<!ELEMENT HR - O EMPTY -- horizontal rule -->
<!ATTLIST HR
 %attrs; -- %coreattrs, %i18n, %events --
 align (left|center|right) #IMPLIED
 noshade (noshade) #IMPLIED
 size %Pixels; #IMPLIED
 width %Length; #IMPLIED
 >

<!ELEMENT P - O (%inline;)* -- paragraph -->
<!ATTLIST P
 %attrs; -- %coreattrs, %i18n, %events --
 %align; -- align, text alignment --
 >

<!ENTITY % OLStyle "CDATA" -- constrained to: "(1|a|A|i|I)" -->

<!ELEMENT OL - - (LI)+ -- ordered list -->
<!ATTLIST OL
 %attrs; -- %coreattrs, %i18n, %events --
 type %OLStyle; #IMPLIED -- numbering style --
 compact (compact) #IMPLIED -- reduced interitem spacing --
 start NUMBER #IMPLIED -- starting sequence number --
 >

<!ENTITY % ULStyle "(disc|square|circle)">
<!ELEMENT UL - - (LI)+ -- unordered list -->
<!ATTLIST UL 
%attrs; -- %coreattrs, %i18n, %events --
 type %ULStyle; #IMPLIED -- bullet style -- compact
(compact) #IMPLIED -- reduced interitem spacing -- >

<!ENTITY % LIStyle "CDATA" -- constrained to: "(%ULStyle;|%OLStyle;)" -->

<!ELEMENT LI - O (%flow;)* -- list item -->
<!ATTLIST LI
 %attrs; -- %coreattrs, %i18n, %events --
 type %LIStyle; #IMPLIED -- list item style --
 value NUMBER #IMPLIED -- reset sequence number --
 >

<!ENTITY % version "version CDATA #FIXED '%HTML.Version;'">

<!ENTITY % html.content "HEAD, BODY">

<!ELEMENT HTML O O (%html.content;) -- document root element -->
<!ATTLIST HTML 
%version; >

For brevity, the element declarations for the inline elements and many block elements have been left out.

DTD Contents Page