Shared Documents: Why We Need DTDs

The well-formedness rules examined in Chapter 2, “The Structure of an XML Document,” and Chapter 3, “XML Must Be Well-Formed,” either ensure that XML processors handle XML documents that satisfy XML’s syntax rules or signal an error indicating that the document isn’t suitable for further processing. For some purposes, that is sufficient.

For many purposes, particularly when documents are being shared among business partners, for example, it is useful for XML documents also to conform to a known, predictable structure. Of course, it is possible to write custom code in Java or some other programming language to make appropriate checks of a received document’s structure. However, it is potentially more convenient to check structure using the validation tools that form part of a validating XML processor.

In XML, a document type definition (DTD) defines the allowed structure of a class of XML documents. A validating XML processor can use the DTD to confirm that a document conforms to the relevant DTD. Using XML-based validation cuts down on the need to write custom code.

Note

Two broad types of XML processor exist. A nonvalidating XML processor checks that documents conform to the rules of XML syntax, but it doesn’t check for any specific structure of elements or attributes. A validating XML processor checks for well-formedness and also checks that the document conforms to a defined structure.



XML documents are ideal for sharing information using a standard syntax. The recipient of information expressed in XML might want to check that the structure of the information received corresponds to what he expects. If the structure of the received information can be checked automatically rather than by writing customized code, this is significantly more efficient.

Document Structure Is Defined in a DTD

The only schema mechanism provided in the XML 1.0 Recommendation is the document type definition (DTD).

Note

A schema is a document that defines the allowed structure, or its variants, of a class of XML documents. Schemas for XML 1.0 documents may be written in non-XML syntax, a DTD, or, more recently in XML syntax, using a variety of schema languages. For example, the W3C XML Schema is described in Chapter 19, “Beyond DTDs—W3C XML Schema.”



A DTD contains markup declarations in two subsets, the internal subset and the external subset. Taken together, these define the allowed structure of a class of XML documents.

Typically, a group of companies or other organizations with a common interest in a particular type of information will agree (after sometimes lengthy discussion) to automate important processes. That will generate a list of documents that they want to exchange and, in turn, agree on a common structure to be used for the exchange of certain types of business or technical information. The formal expression of the agreed-upon structure is a DTD or other type of schema.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset