Document Type Definition (DTD) is an XML document that defines the structure and constraints of other XML documents. It can be used to verify the validity of XML if its content is what is expected. An XML can and should specify its own schema, to ease the validation process. The elements of a DTD are as follows:
- Schema: This represents the root of the document.
- Complex type: It allows an element to have content.
- Sequence: This specifies the child elements that must appear in the described sequence.
- Element: This represents an XML element.
- Attribute: This represents an XML attribute for the parent tag.
This is a sample schema declaration for the Character struct we are using in this chapter:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="character">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" use="required"/>
<xs:element name="surname" type="xs:string" use="required"/>
<xs:element name="year_of_birth" type="xs:integer"/>
<xs:element name="job" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
We can see that it is a schema with an element (character) that is a complex type composed by a sequence of other elements.