Home > Articles > Web Services > XML

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Summary

In this chapter, we have covered the Document Type Definition (DTD) and how it is used to validate XML documents. Well-formed XML documents are documents that are syntactically correct according to the syntax rules of XML. However, in order to be a valid XML document, it must be validated against a DTD using a validating XML parser. A DTD serves as a roadmap for defining what structure a valid XML document should have.

We covered the following items in relation to using DTDs:

  • A DTD may be internal to the XML document or external and referenced by the XML document.

  • A DTD is attached to an XML document through a Document Type Declaration. A Document Type Declaration appears after the XML declaration and before the root element of the XML document. The Document Type Declaration may include a reference to an external DTD, encompass an internal DTD, or both.

  • XML elements are declared and defined within the DTD. Elements are parsed from the top down, and elements in the XML document should appear in the same order they appear in the DTD. Element declarations have a specific set of rules and symbols that may be used in their definitions.

  • XML attributes are declared and defined within the DTD. Attributes are not processed in a top-down fashion, but it is good programming practice to insert them after the element they reference. Attribute declarations have a specific set of types that may be used in their definitions.

  • Entities are used in DTD as storage spaces or placeholders for data. Normally entities are used to store repetitive or bulky data for easy reference. There are four types of entities: internal, predefined, external, and parameter. Notations are used as references to help define the format of the external data.

  • The IGNORE directive is used to indicate blocks of declarations that should not be included when the document is processed.

  • The INCLUDE directive is used to indicate blocks of declarations that should be included when the document is processed. This directive is totally unnecessary to the successful processing of a DTD.

  • Comments may be included in DTDs. Comments in DTDs are used in exactly the same way they are used in HTML.

  • The DTD has several drawbacks that limit its scalability with respect to new and future XML applications. The XML Schema is the new recommendation from the W3C organization for XML validation. The XML Schema will be covered in detail in the next chapter.

Throughout the chapter, we followed a mini case study in which the Human Resources department for Zippy Delivery Service used XML to store employee records. The Human Resources department required a DTD to ensure that all XML records were of a uniform structure. To start, they built a simple DTD that was functional and worked. However, they were able to expand upon and improve their DTD to coincide with the introduction of new DTD topics in this chapter. Ultimately, they produced a DTD that effectively defined all the needs of the Human Resources department and enabled them to build a good roadmap for a valid XML document containing employee records.

  • + Share This
  • 🔖 Save To Your Account