Why use both XSD and DTD for XML?

2020-07-23 06:13发布

问题:

Stackoverflow has a couple of great questions contrasting XSD and DTD and choosing between XSD and DTD. But I came across a data format and library that used both XSD and DTD. The XML documents specify the DTD but the supporting library requires the XSD to encode and decode.

What are the benefits of using an XSD and DTD at the same time?

回答1:

The most significant time I've seen both DTD and XSD used together relates to the example you cite: A sector standards group had defined their XML vocabulary and grammar long ago using DTD, yet particular consumers of the XML wanted to use tools such as JAXB that require a XSD. So, the consumers created a parallel schema using XSD to be able to take advantage of tools or satisfy other dependencies requiring XSD while maintaining compatibility with the schema specified via previously established DTDs.

Other than to address such legacy concerns, don't bother with DTD. New projects should solely use more modern XML schema languages such as XSD, RELAX NG, or Schematron.



标签: xml xsd dtd