- 19 -
Is There Any Way of Making Sure that Data Is Structured in a Particular Way? Can
the Structure of an XML Document Be Checked?
Yes, there is. Since we’re talking about applications like e-commerce where the data
being exchanged must be according to a rigid form, it is necessary to ensure that the
data we’re sending or receiving conforms to a particular structure.
Currently the most common way to structure XML documents is to use an SGML
template format called a
Document Type Definition
(DTD). A DTD is an ugly piece of
code that defines the allowable structures in an XML document. We call it ugly because
its format is nonintuitive and extremely rigid. The analogy is that DTDs are to XML
interpreters (parsers) what the Rosetta stone was to archeologists looking to translate
hieroglyphics.
Having a DTD is not enough—there has to be something that performs the actual check.
A software engine called a
parser
performs the actual check on the data to make sure it
conforms to the DTD. This process is called
validation
. An XML document that conforms
to a DTD is called a
valid
XML document. We take a closer look at creating valid XML
documents in
Chapter 3
.
As we mentioned above, we don’t like DTDs because they’re hard to work with. In the
same way that we think the best way for displaying XML is to use an XML-based
language (XSL), we believe that a schema syntax based on XML is the best way to
describe the structure of a XML document. Currently there are two proposed
specifications being looked at to remedy the shortcomings of DTDs: the XML Data and
XML Data Content Description (DCD). Schemas based on XML are similar in purpose to
DTDs, but the syntax is more friendly and intuitive.