DTD
DTD
DTD
What is DTD?
• DTD defines the rules that set out how the document should be structured, what elements should be
included, what kind of data may be included and what default values to use.
• Multiple documents and applications can share DTDs.
• DTDs use a formal grammar to describe the structure and syntax of an XML document, including the
permissible values for much of that document’s content.
• DTDs:
1. provide a formal and complete definition of an XML vocabulary.
2. are shareable descriptions of the structure of an XML documents.
3. are a way to validate specific instances of XML documents and constraints.
4. are restricted to one DTD per document instance.
5. specifies the validity of each tag.
1
DTD (Document Type Definition)
1. The usual XML tag delimiters ( “<” and “?” ).
2. The exclamation mark ( “!” ) that signifies a special XML declaration.
3. The DOCTYPE keyword.
4. The name of the document element (document_element).
5. One of two legal source keywords.
6. One of two DTD locations to associate an external DTD subset within a document.
7. Some additional declarations referring to the internal subset of the DTD.
<Employee>
</Employee>
2
DTD (Document Type Definition)
ANY Element type may contain any well formed XML data.
EMPTY Element type may contain any text or child elements- only elements
attributes are permitted.
Element Element type contains only child elements no additional text is
permitted.
Mixed Element type may contain text and/or child element.
PCDATA Element type may contain text (character data) only.
Content Models
• Content models are used to describe the structure and content of a given element type.
• The content may be:
1. Character data (PCDATA content).
2. One or more child element types (element-only content).
3. A combination of the two (mixed content).
• The key difference between element content and mixed content is the use of the #PCDATA
keyword.
• If present, the content model is either mixed or PCDATA.
• The absence of this keyword indicates element-only content.
Cardinality
• Cardinality operators define how many child elements may appear in a content model.
• There are four cardinality operators:
Operators Description
[none] The absence of a cardinality operator character indicates that one, and only
one, instance of child element is allowed (required).
? Zero or one element – optional singular element.
* Zero or more element – optional element(s).
+ One or more child elements – required element(s).
Limitations of DTD
• Some limitations of DTD include:
1. DTD are not extensible, unlike XML itself.
2. Only one DTD may be associated with each XML document.
3. DTDs do not work well with XML namespaces.
4. Supports very weak data typing.
5. Limited content model descriptions.
6. No object oriented type object inheritance.
7. A document can override / ignore an external DTD using internal subset.
8. Non-XML syntax.
9. No DOM support.
10. Relatively few older, more expensive tools.
11. Very limited support to modularity and reuse.
12. Too simple ID attribute mechanism (no points to requirements, uniqueness scope, etc)