DTD (DocType Declaration) in one page
 
 
 
 
 
 
 
 
 
 
 
 
 
  Contents:
    Review: DOCTYPE Declaration & DTDs, DTD Example;
    Declarations: ELEMENT Type Declaration, ATTLIST Declaration, ENTITY Declaration, NOTATION Declaration, Conditonal Section;
    Other: DTD Guide Glossary, Related References (Review, Documentation, etc.), Related themes, Miscellaneous;
    Similar Sites: MANUAL, Cheat sheets, HTML, CSS, XML, DTD, JavaScript, W3C DOM, SQL, SSI, Tell a friend, Free Icons, Itlibitum, Corp..
       
                         
 
 
Google
 
DTD Example  
  XML example:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!-- Comments -->
<?xml-stylesheet type="text/css" href="your_documents_css.css" ?>
<?word document="test.doc" ?>
<!--
For internal DTD:
<!DOCTYPE root_element [ <!ELEMENT root_element (#PCDATA)> ]>
-->
<!DOCTYPE root_element SYSTEM "your_documents_dtd.dtd">
<element_0>
  <element_1>
    <element_1_1>...text...</element_1_1>
    <element_1_2>...text...</element_1_2>
  </element_1>
  <element_1>
    <element_1_1>...text...</element_1_1>
    <element_1_2>...text...</element_1_2>
  </element_1>
  <element_2>
    <element_2_1></element_2_1>
    <element_2_2 />
  </element_2>
  <element_3>
    <element_3_1 att_3_1_1="...value...">...text...</element_3_1>
    <element_3_2 att_3_2_1="...value..." att_3_2_2="...value...">...text...;</element_3_2>
    <element_3_3 att_3_3_1="ent1 ent2">...text...</element_3_1>
    <element_3_4 att_3_4_1="...value..." />
  </element_3>
  <element_4>
    <![CDATA[ ...cdata... ]]>
  </element_4>
  <element_5>
    <element_3_1 att_3_3_1="...value...">...text...</element_3_1>
    <![CDATA[ ...cdata... ]]>
  </element_2>
</element_0>

DTDs ("your_documents_dtd.dtd") example:

<!ELEMENT element_0 (element_1, element_2, element_3, element_4, element_5)>
  <!ELEMENT element_1 (element_1_1, element_1_2)>
    <!ELEMENT element_1_1 (#PCDATA)>
    <!ELEMENT element_1_2 (#PCDATA)>
  <!ELEMENT element_2 (element_2_1, element_2_2)>
    <!ELEMENT element_2_1 EMPTY>
    <!ELEMENT element_2_2 EMPTY>
  <!ELEMENT element_3 (element_3_1, element_3_2, element_3_3, element_3_4)>
    <!ELEMENT element_3_1 (#PCDATA)>
      <!ATTLIST element_3_1 att_3_1_1 CDATA>
    <!ELEMENT element_3_2 (#PCDATA)>
      <!ATTLIST element_3_2 att_3_2_1 CDATA "...default_value...">
      <!ATTLIST element_3_2 att_3_2_2 CDATA #REQUIRED>
    <!ELEMENT element_3_3 (#PCDATA)>
      <!ATTLIST element_3_3 att_3_3_1 ENTITIES #REQUIRED>
      <!ENTITY ent1 SYSTEM "http://www.html.su/">
      <!ENTITY ent2 SYSTEM "http://www.css.su/">
    <!ELEMENT element_3_4 EMPTY>
      <!ATTLIST element_3_4 att_3_4_1 CDATA #IMPLIED>
  <!ELEMENT element_4 (#PCDATA)>
  <!ELEMENT element_5 ANY>

 
 
 
 
 
 
 
 
 
 
 
 
 
   DOCTYPE Declaration & DTDs
 

      The document type (DOCTYPE) declaration consists of an internal, or references an external Document Type Definition (DTD). It can also have a combination of both internal and external DTDs. The DTD defines the constraints on the structure of an XML document. It declares all of the document's element typesglossary, children element types, and the order and number of each element type. It also declares any attributes, entities, notations, processing instructions, comments, and PE references in the document.

      A document can use both internal and external DTD subsets. The internal DTD subset is specified between the square brackets of the DOCTYPE declaration. The declaration for the external DTD subset is placed before the square brackets immediately after the SYSTEM keyword.

 
 
 
 
 
 
  The Internal DTD:

<!DOCTYPE root_element [
  Document Type Definition (DTD):
  elements/attributes/entities/notations/
processing instructions/comments/PE references
]>
Rules:
  • The document type declaration must be placed between the XML declaration and the first element (root element) in the documentwell-formedness constraint.
  • The keyword DOCTYPE must be followed by the name of the root element in the XML documentvalidity constraint.
  • The keyword DOCTYPE must be in upper casewell-formedness constraint.
 
 
 
 
 
 
  "Private" External DTDs:

<!DOCTYPE root_element SYSTEM "DTD_location">

      External DTDs are useful for creating a common DTD that can be shared between multiple documents. Any changes that are made to the external DTD automatically updates all the documents that reference it. There are two types of external DTDs: private, and public.

      Private external DTDs are identified by the keyword SYSTEM, and are intended for use by a single author or group of authors.

      Public external DTDs are identified by the keyword PUBLIC and are intended for broad use. The "DTD_location" is used to find the public DTD if it cannot be located by the "DTD_name".

Rules:
  • If any elements, attributes, or entities are used in the XML document that are referenced or defined in an external DTD, standalone="no" must be included in the XML declarationvalidity constraint.

      DTD_location: relative or absolute URL
      DTD_name follows the syntax:
"prefix//owner_of_the_DTD//description_of_the_DTD//ISO 639_language_identifier"

Prefixes are allowed in the DTD name.
Prefix:Definition:
ISOThe DTD is an ISO standard. All ISO standards are approved.
+The DTD is an approved non-ISO standard.
-The DTD is an unapproved non-ISO standard.
 
 
 
  "Public" External DTDs:

<!DOCTYPE root_element PUBLIC "DTD_name" "DTD_location">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   ELEMENT Type Declaration ATTLIST Declaration 
 

      Element type declarations set the rules for the type and number of elements that may appear in an XML document, what elements may appear inside each other, and what order they must appear in.

      Attributes are additional information associated with an element typeglossary. They are intended for interpretation by an application. The ATTLIST declarations identify which element types may have attributes, what type of attributes they may be, and what the default value of the attributes are.

 
  <!ELEMENT name_element allowable_contents> Rules:
  • All element typesglossary used in an XML document must be declared in the Document Type Definition (DTD) using an Element Type Declarationvalidity constraint.
  • An element type cannot be declared more than oncevalidity constraint.
  • The name in the element type's end tagglossary must match the name in the element type's start tagglossarywell-formedness constraint. Element names are case sensitive.
  • The keyword ELEMENT must be in upper casewell-formedness constraint.
Note:
  • The allowable contents of an element type is EMPTY, ANY, Mixed, or children element types.
<!ELEMENT foo (#PCDATA)>
  <!ELEMENT img EMPTY> <!ATTLIST element_name attribute_name attribute_type default_value>

element_name: name of the element to which the attribute applies.

Rules:
  • All attributes used in an XML document must be declared in the Document Type Definition (DTD) using an Attribute-List Declarationvalidity constraint.
  • Attributes may only appear in startglossary or emptyglossary tagswell-formedness constraint.
  • The keyword ATTLIST must be in upper casewell-formedness constraint.

Note:
  • There are three main attribute types; a string type, tokenized types, and enumerated types. They are classified as follows.
<?xml version="1.0"?>

<!DOCTYPE image [
  <!ELEMENT image EMPTY>
  <!ATTLIST image height CDATA #REQUIRED>
  <!ATTLIST image width CDATA #REQUIRED>
]>

<image height="32" width="32"/>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Allowable Contents.
Allowable Contents:Definition:
EMPTYRefers to tags that are empty. For example, the empty IMG tag from HTML may be represented in either of the following ways: <img src="cat.gif"/>, or <img src="cat.gif"></img>well-formedness constraint.
ANYRefers to anything at all, as long as XML rules are followed. ANY is useful to use when you have yet to decide the allowable contents of the element.
children elementsYou can place any number of element types within another element type. These are called children elements, and the elements they are placed in are called parent elements.
Mixed contentRefers to a combination of (#PCDATA) and children elements. PCDATA stands for parsed character data, that is, text that is not markup. Therefore, an element that has the allowable content (#PCDATA) may not contain any children.
 
 
 
 
String Attribute Type
String Attribute Type:Attribute Description:
CDATACDATA stands for character data, that is, text that does not form markup. (example)
Tokenized Attribute Type:
Tokenized Attribute Types: Attribute Description:
IDID is a unique identifier of the attribute. IDs of a particular value should not appear more than once in an XML documentvalidity constraint. An element type may only have one ID attributevalidity constraint. An ID attribute can only have an #IMPLIED or #REQUIRED default valuevalidity constraint. The first character of an ID value must be a letter, '_', or ':'validity constraint. (example)
IDREFIDREF is used to establish connections between elements. The IDREF value of the attribute must refer to an ID value declared elsewhere in the documentvalidity constraint. The first character of an ID value must be a letter, '_', or ':'validity constraint. (example)
IDREFSAllows multiple ID values separated by whitespacevalidity constraint.
ENTITYENTITYs are used to reference data that act as an abbreviation or can be found at an external location. The first character of an ENTITY value must be a letter, '_', or ':'validity constraint. (example)
ENTITIESAllows multiple ENTITY names separated by whitespacevalidity constraint. (example)
NMTOKENThe first character of an NMTOKEN value must be a letter, digit, '.', '-', '_', or ':'validity constraint. (example)
NMTOKENSAllows multiple NMTOKEN names separated by whitespacevalidity constraint.
Enumerated Attribute Types:
Enumerated Attribute Types: Attribute Description:
NOTATIONNOTATIONs are useful when text needs to be interpreted in a particular way, for example, by another application. The first character of a NOTATION name must be a letter, '_', or ':'validity constraint. (example)
EnumeratedEnumerated attribute types allow you to make a choice between different attribute values. The first character of an Enumerated value must be a letter, digit, '.', '-', '_', or ':'validity constraint. (example)
 
 
 
 
 
 
 
  <!ELEMENT ELEMENT element_name EMPTY>

Declaring Empty Elements:
      Empty elements are declared with the category keyword EMPTY.

<?xml version="1.0"?>

<!DOCTYPE student [
  <!ELEMENT br EMPTY>
]>

<br />
<br></br>
 
 
 
 
 
 
  <!ELEMENT element_name (#PCDATA)>

Declaring Elements With Only Character Data:
      Elements with only character data are declared with #PCDATA inside parentheses.

<?xml version="1.0"?>

<!DOCTYPE student [
  <!ELEMENT country (#PCDATA)>
]>

<country>USA</country>
 
 
 
 
 
 
  <!ELEMENT element_name ANY>

Declaring Elements With Any Contents:
      Elements declared with the category keyword ANY, can contain any combination of parsable data.

<?xml version="1.0"?>

<!DOCTYPE student [
  <!!ELEMENT note ANY>
  <!ELEMENT title (#PCDATA)>
]>

<note>Manual <title>DTD</title></note>
 
 
 
 
 
        The "default_value" signifies whether an attribute is required or not, and if not, what default value should be displayed. The possible default values are listed in below.
  <!ELEMENT parent_name (child_name)>
<!ELEMENT child_name allowable_contents>

Declaring Children:
      Children element types are declared using parentheses in the parent element type's declaration.

Rules:
  • The child element must be declared in a separate element type declarationvalidity constraint.
<?xml version="1.0"?>

<!DOCTYPE student [
  <!--'student' must have one child element type 'id'-->
  <!ELEMENT student (id)>
  <!--'id' may only contain text that is not markup in its content-->
  <!ELEMENT id (#PCDATA)>
]>

<student><id>9216735</id></student>
 
Default Values:
Default Value:Description:
#REQUIREDThe attribute must always be includedvalidity constraint. (example)
#IMPLIEDThe attribute does not have to be included. (example)
#FIXED "Default_Value"The attribute must always have the default value that is specifiedvalidity constraint. If the attribute is not physically added to the element tag in the XML document, the XML processor will behave as though the default value does exist. The first character of a default value can be any character except for '&', '<', '"'. It can also be an entity reference (i.e. '&Name;'), or a character referencevalidity constraint. (example)
 
 
 
 
 
 
 
 
 
  <!ELEMENT parent_name (child1_name,child2_name,child3_name)>
<!ELEMENT child1_name allowable_contents>
<!ELEMENT child2_name allowable_contents>
<!ELEMENT child3_name allowable_contents>

Declaring Multiple Children (Sequence):
      Multiple children are declared using commas (,). Commas fix the sequence in which the children are allowed to appear in the XML document.

Rules:
  • All of the children elements must be declared in a separate element type declaration.
<?xml version="1.0"?>

<!DOCTYPE student [
  <!--'student' must contain three child elements in the order listed-->
  <!ELEMENT student (id,surname,firstname)>
  <!--the elements listed below may only contain text that is not markup-->
  <!ELEMENT id (#PCDATA)>
  <!ELEMENT firstname (#PCDATA)>
  <!ELEMENT surname (#PCDATA)>
]>>

<student>
  <id>9216735</id>
  <surname>Smith</surname>
  <firstname>Jo</firstname>
</student>
Predefined Attributes:
Predefined attribute:Description:
xml:langDefines the language code in which the content of the element is written in. The attribute values of xml:lang should follow ISO-639 if they are two-letter codes, and ISO-3166 if they contain two-letter subcodes. Language identifiers registered with the IANAglossary should contain the prefix "I-" or "i-". Any privately used codes should contain the prefix "X-" or "x-".
xml:spacePreserves white space within a document, that is, passes all white space to the application unchanged. Useful when displaying text such as program source code.
 
 
 
 
 
 
 
 
   CDATA Example: ID Example:  IDREF Example: 
  <?xml version="1.0"?>

<!DOCTYPE image [
  <!ELEMENT image EMPTY>
  <!ATTLIST image height CDATA #REQUIRED>
  <!ATTLIST image width CDATA #REQUIRED>
]>

<image height="32" width="32"/>
<?xml version="1.0"?>

<!DOCTYPE student_name [
  <!ELEMENT student_name (#PCDATA)>
  <!ATTLIST student_name student_no ID #REQUIRED>
]>

<student_name student_no="a9216735">
  Jo Smith
</student_name>
<?xml version="1.0" standalone="yes"?>

<!DOCTYPE lab_group [
  <!ELEMENT lab_group (student_name)*>
  <!ELEMENT student_name (#PCDATA)>
  <!ATTLIST student_name student_no ID #REQUIRED>
  <!ATTLIST student_name tutor_1 IDREF #IMPLIED>
  <!ATTLIST student_name tutor_2 IDREF #IMPLIED>
]>

<lab_group>
  <student_name student_no="a8904885">Alex Foo</student_name>
  <student_name student_no="a9011133">Sarah Bar</student_name>
  <student_name student_no="a9216735" tutor_1="a9011133" tutor_2="a8904885">Jo Smith</student_name>
</lab_group>
 
 
 
 
 
  <!ELEMENT parent_name (child_name?)>
<!ELEMENT child's_name allowable_contents>

Declaring Optional Children:
      Optional children are declared using the (?) operator. Optional means zero or one times.

Rules:
  • If the child element is used in the XML document it must be declared in a separate element type declaration.
<?xml version="1.0"?>

<!DOCTYPE student [
  <!--'student' can have zero or one child element of type 'dob'-->
  <!ELEMENT student (dob?)>
  <!--'dob' may only contain text that is not markup in its content-->
  <!ELEMENT dob (#PCDATA)>
]>

<student><dob>19.06.74</dob></student>
 
 
 
 
 
  ENTITY Example:  ENTITIES Example: 
  <?xml version="1.0" standalone="no"?>

<!DOCTYPE experiment_a [
  <!ELEMENT experiment_a (results)*>
  <!ELEMENT results EMPTY>
  <!ATTLIST results image ENTITY #REQUIRED>
  <!ENTITY a SYSTEM "http://www.xml.su/dtd.gif">
]>

<experiment_a>
  <results image="a"/>
<experiment_a>
<?xml version="1.0" standalone="no"?>

<!DOCTYPE experiment_a [
  <!ELEMENT experiment_a (results)*>
  <!ELEMENT results EMPTY>
  <!ATTLIST results images ENTITIES #REQUIRED>
  <!ENTITY a1 SYSTEM "http://www.xml.su/dtd_1.gif">
  <!ENTITY a2 SYSTEM "http://www.xml.su/dtd_2.gif">
  <!ENTITY a3 SYSTEM "http://www.xml.su/dtd_3.gif">
]>

<experiment_a>
  <results images="a1 a2 a3"/>
</experiment_a>
 
 
 
  <!ELEMENT parent_name (child_name*)>
<!ELEMENT child_name allowable_contents>

Declaring Zero or More Children:
      Zero or more children are declared using the (*) operator.

Rules:
  • If the child element is used in the XML document it must be declared in a separate element type declaration.
<?xml version="1.0"?>

<!DOCTYPE student [
  <!--'student' can have zero or more child elements of type 'subject'-->
  <!ELEMENT student (subject*)>
  <!--'subject' may only contain text that is not markup in its content-->
  <!ELEMENT subject (#PCDATA)>
]>

<student>
  <subject>Mathematics</subject>
  <subject>Physics</subject>
  <subject>Chemistry</subject>
</student>
 
 
  NMTOKEN Example: 
  <?xml version="1.0"?>

<!DOCTYPE student_name [
  <!ELEMENT student_name (#PCDATA)>
  <!ATTLIST student_name student_no NMTOKEN #REQUIRED>
]>

<student_name student_no="9216735">
  Jo Smith
</student_name>
 
 
 
 
  NOTATION Example: 
  <?xml version="1.0"?>

  <!DOCTYPE code [
  <!ELEMENT code (#PCDATA)>
  <!NOTATION vrml PUBLIC "VRML 1.0">
  <!ATTLIST code lang NOTATION (vrml) #REQUIRED>
]>

<code lang="vrml">
  Some VRML instructions
</code>
 
  Enumerated Example: 
  <?xml version="1.0"?>

<!DOCTYPE ToDoList [
  <!ELEMENT ToDoList (task)*>
  <!ELEMENT task (#PCDATA)>
  <!ATTLIST task status (important|normal) #REQUIRED>
]>

<ToDoList>
  <task status="important">This is an important task that must be completed</task>
  <task status="normal">This task can wait</task>
</ToDoList>
  <!ELEMENT parent_name (child_name+)>
<!ELEMENT child_name allowable_contents>

Declaring One or More Children:
      One or more children are declared using the (+) operator.

Rules:
  • The child element must be declared in a separate element type declaration.
<?xml version="1.0"?>

<!DOCTYPE student [
  <!--'student' must have at least one child element of type 'subject'-->
  <!ELEMENT student (subject+)>
  <!--'subject' may only contain text that is not markup in its content-->
  <!ELEMENT subject (#PCDATA)>
]>

<student><subject>Mathematics</subject></student>
Predefined Attributes Example: 
  <?xml version="1.0" standalone="yes"?>

<!DOCTYPE document [
  <!ELEMENT document (description,code)>
  <!ELEMENT description (#PCDATA)>
  <!ATTLIST description xml:lang NMTOKEN #FIXED "en">
  <!ELEMENT code (#PCDATA)>
  <!ATTLIST code xml:space (default|preserve) "preserve">
]>

<document>
  <description xml:lang="en">
    The following section of code displays the menu of user choices and gets the user's request.
  </description>
  <code>
    do {
      do {
        disp_menu();
        scanf(" %d", &ans);
      } while ((ans<1) || (ans>3));
    };
  </code>
</document>
 
 
 
 
 
  Default Value Example 1: 
  <?xml version="1.0"?>

<!DOCTYPE ToDoList [
  <!ELEMENT ToDoList (task)*>
  <!ELEMENT task (#PCDATA)>
  <!ATTLIST task status (important|normal) "normal">
]>

<ToDoList>
  <task status="important">This is an important task.</task>
  <task>This is by default a task that has a normal status.</task>
</ToDoList>
 
 
  <!ELEMENT parent_name (child1_name|child2_name)>
<!ELEMENT child1_name allowable_contents>
<!ELEMENT child2_name allowable_contents>

Combinations of Children (Choice):
      A choice between children element types is declared using the (|) operator.

Rules:
  • The child element used in the XML document must be declared in a separate element type declaration.
<?xml version="1.0"?>

<!DOCTYPE student [
  <!--'student' must have 'id' or 'surname' as its child element-->
  <!ELEMENT student (id|surname)>
  <!--the elements listed below may only contain text that is not markup-->
<!ELEMENT id (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
]>

<student><id>9216735</id></student>
Default Value Example 2: 
  <?xml version="1.0"?>

<!DOCTYPE ToDoList [
  <!ELEMENT ToDoList (task)*>
  <!ELEMENT task (#PCDATA)>
  <!ATTLIST task status NMTOKEN #FIXED "monthly">
]>

<ToDoList>
  <task>go to the bank</task>
  <task>pay the phone bill</task>
</ToDoList>
 
 
 
 
 
 
 
 
 
  <!!ELEMENT parent_name (#PCDATA|child1_name)*>

Mixed Content:
      Mixed content is used to declare elements that contain a mixture of children elements and text (PCDATAglossary).

Rules:
  • The same child element typeglossary may only appear once in a mixed content declarationvalidity constraint.
  • If a child element is used in the XML document, it must be declared in a separate element type declarationvalidity constraint.
  • The (#PCDATA) and children element declarations must be separated by the (|) operatorwell-formedness constraint.
  • (#PCDATA) must come first in the mixed content declarationwell-formedness constraint.
  • The operator (*) must follow the mixed content declaration if children elements are includedwell-formedness constraint.
Note:
  • Non-markup text (PCDATA) can be placed anywhere (before, between or after children elements).
  • The children elements can be placed in any order.
Example 1:

<?xml version="1.0"?>

<!DOCTYPE student [
  <!ELEMENT student (#PCDATA|id)*>
  <!ELEMENT id (#PCDATA)>
]>

<student>
  Here's a bit of text mixed up with the child element.
  <id>9216735</id>
  You can put text anywhere, before or after the child element.
  You don't even have to include the 'id' element.
</student>

Example 2:

<?xml version="1.0"?>

<!DOCTYPE student [
  <!ELEMENT student (#PCDATA|id|surname|dob)*>
  <!ELEMENT id (#PCDATA)>
  <!ELEMENT surname (#PCDATA)>
]>

<student>
  You can put text anywhere. You can also put the elements in any order in the document.
  <surname>Smith</surname>
  And, you don't have to include all the elements listed in the element declaration.
  <id>9216735</id>
</student>
  #IMPLIED Example:  #REQUIRED Example:  #FIXED Example: 
  <?xml version="1.0"?>

<!DOCTYPE contacts [
  <!ELEMENT contact EMPTY>
  <!ATTLIST contact fax CDATA #IMPLIED)>
]>

<contacts>
  <--Valid XML:-->
  <contact fax="555-667788" />

  <--Valid XML:-->
  <contact />
</contacts>
<?xml version="1.0"?>

<!DOCTYPE contacts [
  <!ELEMENT contact EMPTY>
  <!ATTLIST person number CDATA #REQUIRED>
]>

<contacts>
  <--Valid XML:-->
  <person number="5677" />

<--Invalid XML:
  <person />
-->
</contacts>
<?xml version="1.0"?>

<!DOCTYPE contacts [
  <!ELEMENT contact EMPTY>
  <!ATTLIST sender company CDATA #FIXED "IBM">
]>

<contacts>
  <--Valid XML:-->
  <sender company="IBM" />

<--Invalid XML:
  <sender company="Microsoft" />
-->
</contacts>
 
 
 
 
 
 
 
 
 
 
 
 
 
  ENTITY Declaration 
        Entities reference data that act as an abbreviation or can be found at an external location. Entities help to reduce the entry of repetitive information and also allow for easier editing (by reducing the number of occurrences of data to edit). There are two types of entity declarations: GENERAL entity declarations, and PARAMETER entity declarations.
 
 
        The types of general entities include:
  • INTERNAL (PARSED)
  • EXTERNAL (PARSED)
  • EXTERNAL (UNPARSED)
      The types of parameter entities include:
  • INTERNAL (PARSED)
  • EXTERNAL (PARSED)
Rules:
  • Parameter entity references may not be used within markup in an internal DTDwell-formedness constraint.
 
 
 
 
 
 
 
 
  <!ENTITY name "entity_value">

      INTERNAL (PARSED) GENERAL ENTITY Declaration: Internal parsed entities generally reference text. The correct definition is that they refer to data that an XML processor has to parse.

entity_value: any character that is not an '&', '%' or ' " ', a parameter entity reference ('%Name;'), an entity reference ('&Name;') or a Unicodeglossary character reference.
<?xml version="1.0" standalone="yes" ?>

<!DOCTYPE author [
  <!ELEMENT author (#PCDATA)>
  <!ENTITY js "Jo Smith">
]>

<author>&js;</author>
  NOTATION Declaration 
  <!NOTATION name SYSTEM "URI">

<!NOTATION name PUBLIC "public_ID">

<!NOTATION name PUBLIC "public_ID" "URI">

      NOTATIONS are used to identify the format of unparsed entities (non-XML data), elements with a notation attribute, or specific processing instructions.
  • URI: In practice, this is a URL where the external notation can be found.
  • public_ID: This may be used by an XML processor to generate an alternate URI where the external notation can be found. If it cannot be found at this URI, the XML processor must use the normal URI.
Unparsed Entity Example:

<?xml version="1.0" standalone="no" ?>

<!DOCTYPE img [
  <!ELEMENT img EMPTY>
  <!ATTLIST img src ENTITY #REQUIRED>
  <!ENTITY logo SYSTEM "http://www.xml.su/logo.gif" NDATA gif>
  <!NOTATION gif PUBLIC "gif viewer">
]>

<img src="logo"/>

Notation Attribute Example:

<?xml version="1.0"?>

<!DOCTYPE code [
  <!ELEMENT code (#PCDATA)>
  <!NOTATION vrml PUBLIC "VRML 1.0">
  <!ATTLIST code lang NOTATION (vrml) #REQUIRED>
]>

<code lang="vrml">Some VRML instructions</code>

 
 
 
 
 
 
  <!ENTITY name SYSTEM "URI">
<!ENTITY name PUBLIC "public_ID" "URI">
      EXTERNAL (PARSED) GENERAL ENTITY Declaration: External parsed entities generally reference text. The correct definition is that they refer to data that an XML processor has to parse. External entities are useful for creating a common reference that can be shared between multiple documents. Any changes that are made to external entities are automatically updated in the documents they are referenced. There are two types of external entities: private, and public. Private external entities are identified by the keyword SYSTEM, and are intended for use by a single author or group of authors. Public external entities are identified by the keyword PUBLIC and are intended for broad use.
  • URI: In practice, this is a URL where the external parsed entity can be found.
  • public_ID: This may be used by an XML processor to generate an alternate URI where the external parsed entity can be found. If it cannot be found at this URI, the XML processor must use the normal URI.
Example 1:
<?xml version="1.0" standalone="no" ?>

<!DOCTYPE copyright [
  <!ELEMENT copyright (#PCDATA)>
  <!ENTITY c SYSTEM "http://www.xml.sut/copyright.xml">
]>

<copyright>&c;</copyright>

Example 2:
<?xml version="1.0" standalone="no" ?>

<!DOCTYPE copyright [
  <!ELEMENT copyright (#PCDATA)>
  <!ENTITY c PUBLIC "-//W3C//TEXT copyright//EN"
"http://www.w3.org/xmlspec/copyright.xml">
]>

<copyright>&c;</copyright>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  Conditonal Section 
  <![ IGNORE [
markup declarations
]]>

<![ INCLUDE [
markup declarations
]]>
      A way of including or excluding sections in the DTD is to use conditional sections. Conditional sections are of most use when linked to a parameter entity reference, and may only be used in an external DTD subset. The two conditional section statements are IGNORE and INCLUDE.
Rules:
  • Conditional sections may only be used in external DTD subsetswell-formedness constraint.
  • Conditional sections must wrap around entire declarationswell-formedness constraint.
Note:
  • The IGNORE declaration takes precedence over INCLUDE. If an IGNORE statement is nested inside an INCLUDE statement, the contents of the IGNORE statement will still be ignored.
<!ENTITY % draft "INCLUDE">
<!ENTITY % final "IGNORE">

<![%draft;[
  <!ELEMENT book (title,author,summary)>
]]>

<![%final;[
  <!ELEMENT book (comments*,title,author,summary)>
]]>

<!ELEMENT comments (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT summary (#PCDATA)>
 
 
  <!ENTITY name SYSTEM "URI" NDATA name>
<!ENTITY name PUBLIC "public_ID" "URI" NDATA name">
    EXTERNAL (UNPARSED) GENERAL ENTITY Declaration: External unparsed entities generally reference non-XML data. The 100% correct definition is that they refer to data that an XML processor does not have to parse.
  • URI: In practice, this is a URL where the external parsed entity can be found.
  • public_ID: This may be used by an XML processor to generate an alternate URI where the external parsed entity can be found. If it cannot be found at this URI, the XML processor must use the normal URI.
Example 1:
<?xml version="1.0" standalone="no" ?>

<!DOCTYPE img [
  <!ELEMENT img EMPTY>
  <!ATTLIST img src ENTITY #REQUIRED>
  <!ENTITY logo SYSTEM "http://www.xml.su/logo.gif" NDATA gif>
  <!NOTATION gif PUBLIC "gif viewer">
]>

<img src="logo"/>

Example 2:
<?xml version="1.0" standalone="no" ?>

<!DOCTYPE img [
  <!ELEMENT img EMPTY>
  <!ATTLIST img src ENTITY #REQUIRED>
  <!ENTITY logo PUBLIC "-//W3C//GIF logo//EN" "http://www.w3.org/logo.gif" NDATA gif>
  <!NOTATION gif PUBLIC "gif viewer">
]>

<img src="logo"/>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  DTD Guide Glossary 
  application       A self-contained program that performs a specific function directly for the user. An example of an application is XMLwriter. It is a standalone program that allows you to edit XML files as well as other text files.
  <!ENTITY % name "entity_value">       INTERNAL (PARSED) PARAMETER ENTITY Declaration: Internal parameter entity references are used to declare entities existing only in the DTD.
  • entity_value:: any character that is not an '&', '%' or ' " ', a parameter entity reference ('%Name;'), an entity reference ('&Name;') or a Unicodeglossary character reference.
Note:
  • Note the use of external DTD examples above. Parameter entity references may not be used within markup in an internal DTDwell-formedness constraint.
Example 1:

<!--external DTD example-->
<!ENTITY % p "(#PCDATA)">
<!ELEMENT student (id,surname,firstname,dob,(subject)*)>
<!ELEMENT id %p;>
<!ELEMENT surname %p;>
<!ELEMENT firstname %p;>
<!ELEMENT dob %p;>
<!ELEMENT subject %p;>

Example 2:
<!--external DTD example-->
<!ELEMENT author (#PCDATA)>
<!ENTITY % js "Jo Smith">

<!--note that the general entity statement below is used to reference a parameter entity-->
<!ENTITY wb "written by %js;">

Example 3:
<!--external DTD example-->
<!ENTITY % info "(id,surname,firstname)">
<!ELEMENT lab_group_A %info;>
<!ELEMENT lab_group_B %info;>
<!ELEMENT lab_group_C %info;>
 
  attribute       Attributes are inserted in start or empty element tags in the form attribute_name="attribute_value". They are additional information about an element, intended for interpretation by an application. An example of an attribute is <img src="logo.gif"/>, where src is the attribute_name, and logo.gif is the attribute_value.
 
 
 
  attribute-list (ATTLIST) declaration       Attribute-list declarations are placed inside a DTD. They specify what attributes are allowed in an XML document, to which element they belong, and what the default value of an attribute may be. An example of an ATTLIST declaration is <!ATTLIST img src EMPTY>.
 
 
  CDATA       Character data, or text that does not need to be parsed. Markup within CDATA sections will not be interpreted as markup.
 
  child element       An element nested inside another (parent) element. For example:
<parent_element>
  <child_element>
  </child_element>
</parent_element>
 
 
 
 
  document type (DOCTYPE) declaration       Used to contain an internal DTD, or point to an external DTD.
  Document Type Definition       A set of rules describing the structure of an XML document. The document must conform to these rules in order to be valid.
 
  DTD       See Document Type Definition.
  empty tag       An element that has no content. In XML, an empty tag follows the syntax: <name></name> or <name/>.
 
  end tag       The closing tag of an element. It follows the syntax: </name>, and must match the name in the start tag to be well-formed XML.
 
  element type       The name that appears in a start, end or empty tag. In the following example there are three elements but only two element types:
<scholar>
 <sex>girl</sex>
 <sex>boy</sex>
</scholar>
<!ENTITY % name SYSTEM "URI">
%name;

<!ENTITY % name PUBLIC "public_ID" "URI"">
%name;

    EXTERNAL (PARSED) PARAMETER ENTITY Declaration: External parameter entity references are used to link external DTDs. There are two types of external entities: private, and public. Private external entities are identified by the keyword SYSTEM, and are intended for use by a single author or group of authors. Public external entities are identified by the keyword PUBLIC and are intended for broad use.

  • URI: In practice, this is a URL where the external parameter entity can be found.
  • public_ID: This may be used by an XML processor to generate an alternate URI where the external parameter entity can be found. If it cannot be found at this URI, the XML processor must use the normal URI.
<?xml version="1.0" standalone="no"?>

<!DOCTYPE student [
  <!ENTITY % student SYSTEM "http://www.university.com/student.dtd">
  %student;
]>
 
 
 
 
 
  ELEMENT type declaration       Element type declarations are placed inside a DTD. They specify what elements are allowed in an XML document, and what their content may be. An example of an ELEMENT declaration is <!ELEMENT student (id,surname)>.
 
 
  ENTITY declaration       Entity declarations are placed inside a DTD. They contain the abbreviation to be used for an entity, and the text to be substituted for that abbreviation. They may also contain a URI if the text or data is stored at a remote location. An example of an ENTITY declaration is <!ENTITY js "Jo Smith">.
 
 
  external DTD       A DTD that is contained in another file which may reside at a remote location.  
  general entity reference       An entity used in the content of an XML document. General entities follow the syntax '&name;'.
  internal DTD       A DTD that is located within the XML document.
  NOTATION declaration       Notation declarations are placed inside a DTD. They are used to identify the format of non-XML data, and name (or point to) applications that will interpret the data. An example of a NOTATION declaration is <!NOTATION gif PUBLIC "gif viewer">.
   Using Entities Within Entities: 
 

CORRECT Example:

<?xml version="1.0"?>

<!DOCTYPE author [
  <!ELEMENT author (#PCDATA)>
  <!ENTITY email "josmith@theworldaccordingtojosmith.com">
  <!--the following use of a general entity is legal if it is used in the XML document-->
  <!ENTITY js "Jo Smith &email;">
]>

<author>&js;</author>

INCORRECT Example:

<!--the two entity statements are infinitely recursive-->
<!ENTITY email "user@user.com &js;">
<!ENTITY js "Jo Smith &email;">
  PCDATA       Parsed character data. Text that is not markup that is processed by a parser.
  start tag       The opening tag of an element. It follows the syntax: <name>, and must match the name in the end tag to be well-formed XML.
  Related References 
  Documentation
  • Extensible Markup Language (XML) 1.0 (Third Edition) >>>
  • HTML 4 Document Type Definition >>>
  • XHTML 1.0 DTDs >>>
 
 
 
 
 
 
 
 
   Related themes  Miscellaneous  Predefined GENERAL Entities:
  XML
HTML
CSS
Free archive of icons for download (IconsFree.org)
© 2006 MANUAL.SU (Itlibitum, Corp.)
 
Valid XHTML 1.0 Transitional   Valid CSS!
 Symbol:   Predefined Entities:            How to Declare These Entities in a DTD:          
 < &lt; <!ENTITY lt "&#38;#60;">
 > &gt; <!ENTITY gt "&#62;">
 & &amp; <!ENTITY amp "&#38;#38;">
 ' &apos; <!ENTITY apos "&#39;">
 " &quot; <!ENTITY quot "&#34;">