Is DTD deprecated?

2019-07-15 05:16发布

问题:

In What is difference between XML Schema and DTD?, two answerers state that DTD "is deprecated". One of them, user vtd-xml-author, states that

DTD is pretty much deprecated because it is limited in its usefulness [...]

at which user Jesse Chisholm comments

Deprecated? No. [XDR is deprecated] Going out of fashion? Maybe [...]

In What is DTD exactly?, user AlexR comments on an answer as follows:

Note that DTD is deprecated in favor of the more declarative and powerful XSD.

In this case, no-one shows up to disagree.

So is DTD deprecated, or not? It is surely a matter of fact, not of opinion. Presumably it is the W3C or some other standards body who would have the authority to determine whether DTD is in fact deprecated. Of course, the use of DTD in a given context (for example, a particular software system) might be deprecated without DTD itself being deprecated outside of that (or any) context.

回答1:

DTD is not officially deprecated, but there are better choices for specifying an XML vocabulary and grammar than DTD now.

Colloquially, deprecated is often used to refer to an old way that's no longer encouraged. In such a sense, one might say that DTD is deprecated. XSD is much more expressive than DTD. (RELAX NG and Schematron would be better choices as well.) Furthermore, XSD adoption has long surpassed DTD for specifying XML vocabularies and grammars across many sectors.

Technically, however, deprecated is typically applied to an official act by a party responsible for a standard, API, library, or other artifact under its control. W3C has never declared DTD to be deprecated, therefore it is not technically correct to say that DTD is deprecated.

Semantics aside, choose XSD (or RELAX NG or Schematron) for any new XML vocabulary and grammar work you begin. DTD doesn't have to be officially deprecated to be a poor choice at this point in time.