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?
-
You should specify which paper you are referring to and provide a sufficiently long verbatim quotation, as well as describe the context of the quote. It’s now pure guesswork to try to analyze what they may have meant. – Jukka K. Korpela Mar 06 '14 at 17:19
1 Answers
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.

- 23,209
- 4
- 50
- 65
-
-
I use Oxygen XML Editor, in Mac OS. I believe XML Spy also achieves that. But it has to be well-formed XML (XHTML). Anyway, if you want a DTD or Schema for XHTML you don't have to generate one. You can refer to it or download it from W3C, the [XML Schema](http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd) or the [DTD](http://www.w3.org/TR/xhtml1/dtds.html). DTD extraction would be useful if for some reason you have to use a DTD (not a XML Schema) and your HTML document has foreign namespaced elements (like `svg:svg`, for example). – helderdarocha Mar 06 '14 at 17:22
-
DTDs don't support namespaces but they can validate prefixed tags. In this case, if you can use XMLSchema it's better since you can associate several languages in one document, using namespaces associated to different schemas and prefixing foreign tags. – helderdarocha Mar 06 '14 at 17:23