Question

I know what a DTD is, as described in this question. I was reading a paper, and they were talking about extracting the DTD from a XHTML document or its schema. I was wondering what does it mean? Can anybody give me an example for clarification?

Was it helpful?

Solution

A DTD is a schema, since it describes the structure of the data; it's analogous to a class. One XHTML document is one instance, analogous to an object. XHTML is also XML. So you could generate a DTD (or a XML Schema) which describes the contents of elements and attributes based on that document only, and the generated DTD or XML Schema will validate it.

But there is no guarantee that this generated schema will validate other XHTML documents. If you add an extra <p> to your instance, or if you use a valid XHTML tag that was not present in the instance you used to generate the DTD, then validation will fail for this second document.

If you have another schema that validates your XHTML, for example, the W3C XML Schema for XHTML, then you can generate from it a DTD that will validate all XHTML instances you create (in this case, download or use the DTD available at W3C).

There are several tools that generate DTDs from XML Schemas or from documents. If you search you will find several free and commercial options.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top