Valid XML Documents
The primary difference between valid and well formed XML is that valid XML must conform to a document type definition (DTD). Well formed XML does not need to conform to a DTD. Valid XML requires a DTD.
Valid XML documents enable document authoring, processing, storage and display to exist in a structured environment. Authors must create documents against a pre-defined structure. This structure allows a clear document model.
Document Type Definitions (DTD)
A DTD is a set of rules that describe the structure of XML elements. Software may need to read these rules before processing and displaying a document. These rules generally state the name and contents of each element and in which contexts it can and must exist. Paragraph elements might be defined as containing keyword and code elements and as existing within section and note elements. Valid XML documents may employ certain advanced features of XML, which are not accessible to well formed documents, because of their lack of a DTD. These features can significantly improve the usability of a document, including: linking mechanisms, entities and attributes. The DTD is associated with an XML document in the document type declaration, which appears at the top of the XML file. The following DTD is an example of a customer DTD:
<?xml version="1.0" encoding="US-ASCII"?>
<!ELEMENT customer (lastName?,firstName?,streetAddress?,email?,zip?)>
<!ELEMENT customerRequest (request,customer?)>
<!ELEMENT customerResponse (response,customer?)>
<!ELEMENT lastName (#PCDATA)>
<!ELEMENT firstName (#PCDATA)>
<!ELEMENT streetAddress (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT zip (#PCDATA)>
<!ELEMENT request (#PCDATA)>
<!ELEMENT response (#PCDATA)>
Last modified date: 01/29/2015