Enforcing XML Document Structure

If XML is used to transfer information between applications, there needs to be a mechanism for ensuring that the XML is not only syntactically correct but also is structurally correct. In fact, there are two common mechanisms for this:

  • Document Type Definitions

  • XML Schemas

Document Type Definition (DTD)

A Document Type Definition (DTD) is a way of defining the structure of an XML document. DTD elements can be included in the XML document itself or in a separate external document. The syntax used to define a DTD is different from XML itself.

The following is an example DTD that describes the jobSummary XML:

 <!DOCTYPE jobSummary> <!ELEMENT jobSummary (job*)> <!ELEMENT job (location, description?, skill*)> <!ATTLIST ...

Get Sams Teach Yourself J2EE™ in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.