A DTD specifies application-specific syntax. It cannot specify constraints like "this piece of data is a year after 2000" or even "this piece of data is a number."
In an XML document, the DTD to use is given by something like a special tag, for example
<!DOCTYPE person SYSTEM "http://www.ucsd.edu/person.dtd">In general DTDs can be thousands of lines long, but the basics are simple. For example:
<!ELEMENT person (name, job*)>#PCDATA means parsed character data. In this type of free text, special characters must be written as < and & Any XML parser translates these before passing the text to any application using the parser.
<!ELEMENT name (first, middle?, last)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT paragraph (#PCDATA | name | footnote | date)*>
<!ELEMENT image EMPTY>
A section written <![CDATA[ text ]]> doesn't need escaped characters. VoiceXML uses CDATA to include grammars for voice recognition.
The number of appearances allowed for a nested element is indicated by * or ? or +. Parentheses indicate grouping.
If #PCDATA is one choice among others, the content of the element
is said to be mixed.
<!ATTLIST image source CDATA #REQUIREDThe meaning of the modifier #REQUIRED is obvious. #IMPLIED means the attribute is optional, and no default value is provided. A literal value is a default for when the attribute is not given a value.
width NMTOKEN #IMPLIED
height NMTOKEN #IMPLIED
format CDATA #FIXED "jpeg"
alt CDATA "No caption provided."
catalogno ID #REQUIRED
owner IDREF "Unknownn_owner"
>
CDATA means that the content of an attribute value can be aribtrary
text inside quotation marks, while NMTOKEN means the content must
be a legal XML name.
Conversely, the type IDREF means that the attribute value must be an XML name that is given elsewhere in the document as the value of an ID attribute.
Ids and reference to ids are used to establish many-to-many relationships
between entities inside a document. Consider converting a database
of multiple tables into a single XML document...
Recent browsers (IE 5.5 and Netscape 6.0) handle XHTML, though not all
do so perfectly. Unfortunately application developers have to still
cater to older browsers.
<?xml version="1.0">IE5 and later can display XML documents with or without a stylesheet.
<?xml-stylesheet href="person.css" type="text/css"?>