XML DTD
XML Document Type Declaration, commonly it is called DTD. It is used to describe XML language absolutely. When we create DTD, we are creating a syntax rules for any XML documents that uses the DTD. Syntax
<! DOCTYPE element DTD identifier
[
decleration1
decleration2
. . . . .
]>
- It start with <! DOCTYPE delimiter.
- An element tells parser to parse document from specified root element.
Internal DTD
A DTD is referred to as an internal DTD if elements are declared within the XML files. Here declaration works independent of an external source. Syntax<! DOCTYPE root-element [element-declarations]>
<?xml version=?1.0??>
<! DOCTYPE student[
<!ELEMENT students (name, class, section)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT class (#PCDATA)>
<!ELEMENT section (#PCDATA)>
]>
<student>
<name> Rohit sharma</name>
<class>10</class>
<section>?B?</section>
</student>
External DTD
In external DTD elements are declared outside the xml file. The URL can point to either a local or remote file using relative and absolute refrencesrespectively. It means declaration includes information from the external source. Syntax<! DOCTYPE root-element SYSTEM "file-name">
<?xml version=?1.0??>
<!DOCTYPE student SYSTEM "student.dtd">
<student>
<name> Rohit sharma</name>
<class>10</class>
<section>?B?</section>
</student>
<!ELEMENT student (name, class, section)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT class (#PCDATA)>
<!ELEMENT section (#PCDATA)>
System identifiers
It enable us to specify the location of an external file containing DTD declarations.<!DOCTYPE name SYSTEM "address.dtd" [. . . .]>
Public identifiers
It provide the mechanism to locate DTD resources.<!DOCTYPE name PUBLIC "-//Beginning XML// DTD Address Example//EN">