Why Validate an XML Document?

A validating parser will check if an XML document references a DTD. If it does, the parser will check the content and structure of the document against the DTD.

It's easy to understand why a processor will refuse to display a document that is not well-formed, but why even bother validating a document against a DTD? If XML documents are designed for use over the Internet, why bother sending along the accessory baggage of a DTD? Why not just display the document?

These are all good questions. If the purpose of XML was just to provide a vehicle for document display, there would be no need to bother with a DTD. However, XML documents are not just vehicles for display. They are vehicles for storing and structuring content. ...

Get XML Unleashed 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.