DTD stands for description of type of document. It specifies the legal structure of an XML text. document structure is specified with a set of legal elements and attributes.
The principal aim is to describe the XML document structure. This includes a set of legal elements and with their help, describes the structure.
You'll need to check the validation before continuing with XML DTD. If an XML document includes the correct syntax, it is considered "well-formed."
A well-formed, valid XML document is one that was validated against DTD.
Visit http://www.xmlvalidation.com to validate the XML file.
Let's take an illustration of an XML document well-formed and real. It follows any of the DTD laws.
<?xml version="1.0"?> <!DOCTYPE employee SYSTEM "employee.dtd"> <employee> <firstname>Phptpoint</firstname> <lastname>Noida</lastname> <email>[email protected]</email> </employee>
For the case above the DOCTYPE declaration applies to an external DTD file. The file contents are shown in paragraph below.
<!ELEMENT employee (firstname,lastname,email)> <!ELEMENT firstname (#PCDATA)> <!ELEMENT lastname (#PCDATA)> <!ELEMENT email (#PCDATA)>
<!DOCTYPE employee :It determines employee to be the root aspect of the document.
<!ELEMENT employee:It determines that the employee variable includes 3 "first name , last name and e-mail" elements.
<!ELEMENT firstname:It determines the first name element to be typed # PCDATA. (Type of data which is parse-able).
<!ELEMENT lastname:It determines that # PCDATA is typed with the last name element. (Type of data which is parse-able).
<!ELEMENT email:It determines that # PCDATA is typed in the email element. (Type of data which is parseable).
A doctype declaration may also describe unique strings which can be included in XML file.
There are three sections of an entity:
Syntax to declare entity:
<!ENTITY entity-name "entity-value">
Let's see a code to define the ENTITY in doctype declaration.
<?xml version="1.0" standalone="yes" ?> <!DOCTYPE author [ <!ELEMENT author (#PCDATA)> <!ENTITY sj "Sonoo Jaiswal"> ]> <author>&sj;</author>