In this tutorial you will learn about DTD Introduction and how to use in XML. DTD (Document Type Definition) is a type of document schema and define the structure of XML documents.
DTD is a provide a framework for validating XML documents. You can create DTD file that are shareable to a different application.
In XML you can define tags without defining what tag are legal. But defined XML document structure must be conform to, if you specifies DTD rules.
DTD does not identify root element. Manually you want to inform (write) root element. In sort DTD contains number of rules that rules must be follow XML document.
DTD defines following three rules,
A Well-formated file is follow general XML rules like every open tag must be closed, tags must be properly nested, empty tag must be end with '/>', attribute values must be enclosed either single or double quotes etc.
Valid XML file is conforms to a specific structure and that XML file have DTD that specifies used tags, attributes those are tag contains.
Types of DTD declarations
You can specifies DTD either internally within XML document or externally.
External DTD : You can write rules in a separate file (with .dtd extension). later this file linked to a XML document. This way you can linked several XML documents refer same DTD rules.
Internal DTD : You can write rules inside XML document using <!DOCTYPE ... > declaration. Scope of this DTD within this document. Advantages is document validated by itself without external reference.
In DTD, you can write comments over one or more lines. comments are enclosed by a pair of
Comment Example :