Home > Articles > Programming

  • Print
  • + Share This

Well-Formed Versus Valid Documents

The first requirement of an XML document is that it must be well formed. Tags much be nested properly, attributes must be enclosed in quotation marks, it must have a single root element, and so on. We've dealt with all that in the first two chapters of this book.

But nothing that we've done says anything about requirements for the actual content of the data. This is a case where extensibility is a double-edged sword. We can put whatever we want into our XML document, as long as it's well formed. Unfortunately, so can anybody else.

For a single person working alone, this isn't an issue. When a second, or third, or three hundredth person enters the mix, however, slight (or even not-so-slight) differences in the way that data is represented can add up quickly. What's more, although they might be a nuisance in terms of displaying data, those differences are deadly when it comes to actually working with it.

To DTD or Not to DTD

For this reason, the XML 1.0 standard includes Document Type Definitions, or DTDs. A DTD can be either included in a document or associated with it (similar to the way we associated style sheets), allowing a validating parser to check the structure and content of the document.

valid document—A valid XML document conforms to the structure defined in a DTD or other definition.

validating parser—A validating parser checks an XML file not just for well-formedness, but for differences from a DTD or other definition.

DTDs were, and still are, essential to serious XML development, but they have a number of problems and limitations.

First, the syntax is different from XML syntax, making it a bit confusing for new users. Second, although DTDs can be powerful, there are still things developers need to do that simply can't be accomplished with a DTD.

For this reason, it wasn't long before other initiatives started to improve on the functionality of DTDs. Many of them have come and gone, but two that seem to have legs are XML Schema, which uses XML syntax and adds a great deal of functionality to the process, and a similar proposal, RELAX, out of Japan. It is likely that in the long run, one of these will take the place of DTDs for development moving forward.

None of these, however, has yet reached the status of "standard," so we are still going to need to take a look at DTDs. Although Xerces includes support for much of XML Schema, it's not yet complete or final. Besides, DTDs are used to describe XML vocabularies that can be used for data interchange within industries or for other purposes, so any serious XML developer is going to have to deal with them sooner, rather than later.

We'll look at the basics of DTDs, and when we come up against their limitations, we'll look at how XML Schema can help us overcome them.


What Is a "Standard," Anyway?

In the world of the Internet, as in life, it's important for people to be able to understand one another. This is particularly important as people strive to interconnect diverse systems. Because of this, a standard way of communicating is crucial.

But although we throw the word around quite casually, it does actually have a real meaning. Technically, a standard is a document that has been approved by a national or international standards body, such as the International Organization for Standards (ISO) or the American National Standards Institute (ANSI).

The World Wide Web Consortium (W3C) is not a formal standards body.

"Wait a minute," you might be thinking. "How can the W3C not be a standards body when it publishes the standards for the Web and the Internet?"

Simple: It doesn't. The W3C publishes Recommendations, and it's very clear about that. Although, if desired, a W3C Recommendation could be submitted to a formal standards body such as ISO, they typically aren't, and with good reason.

That reason is also simple: It doesn't matter.

What makes a standard isn't the voting body that approves it, but rather the fact that everyone (or almost everyone) is using it. For instance, RELAX might be submitted for Fast Track approval by ISO and might be official before XML Schema gets through the process at W3C. But if nobody uses it, what difference does it make?

The W3C Recommendations are typically considered to be informal standards if they are what's in use, as in "the standard" way of doing something. Like most resources, we'll use "standard" and "recommendation" interchangeably, but it helps to keep the difference in mind.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.