The DTD specifies which elements may occur in an XML file, and in which way the elements should be ordered or nested. The sample DTD specifies that an address contains one or more address_record elements, which in turn can contain a name, street, city, and email. street and city are defined as optional elements.
<!ELEMENT address ( address_record+ )> <!ELEMENT address_record ( name, street?, city?, email )> <!ELEMENT name (#PCDATA )> <!ELEMENT street (#PCDATA )> <!ELEMENT city (#PCDATA )> <!ELEMENT email (#PCDATA )>
When loading an XML file, Text Control checks whether the XML code is valid, i.e. adheres to the rules specifed in the DTD. An error will occur if it does not, like in this example, where the required <name> has been removed:
<?xml version="1.0"?> <? XML:stylesheet type="text/css" href="address.css"?> <!DOCTYPE address SYSTEM "address.dtd"> <address> <address_record> <street>Baker Street</street> <city>London</city> <email>firstname.lastname@example.org</email> </address_record> </address>
Loading the above XML code will raise an error:
This strict error checking is considered one of the major strengths of XML, as it ensures that a document will always have a certain structure, and thus can be processed by other applications.