本文介绍了如何在 DTD 和 XSD 之间进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 DTD 或 XSD 来描述我的 XML 文档.我听说 XSD 比 DTD 更好,因为它们支持命名空间和数据类型,而且 DTD 更老.

I want to use either a DTD or an XSD to describe my XML document. I've read that XSDs are better than DTDs since they support namespaces and data types, and that DTDs are older.

这是否意味着我应该只使用 XSD 来满足所有未来的需求,而完全忽略 DTD 作为一个选项?我是否应该费心学习 DTD 的结构?

Does this mean that I should only use XSDs for all future needs and totally ignore DTD as an option? Should I even bother learning the structure of DTDs?

在选择 XSD 和 DTD 时应该考虑哪些因素?

What factors should I consider when choosing between XSD and DTD?

推荐答案

作为一个单独的练习来学习 DTD 可能很重要,只是为了了解它们是如何工作的,以防万一你在其他地方遇到它们,这样你就可以欣赏XSD 试图解决的一些问题.

It's probably important to learn DTDs as a separate exercise, just for the knowledge of how they work in case you encounter them somewhere else, and so that you can appreciate some of the things that XSD was trying to solve.

但是,就您当前描述 XML 文档的目的而言,确实坚持使用 XSD.

However, for your current purposes of describing an XML document, indeed stick to XSDs.

除了具有更丰富的功能集(如您提到的,包括数据类型和名称空间)之外,它们本身也是 XML 文档,这非常有用.因为它们是 XML,所以您可以更轻松地检查它们的格式正确性和有效性,并且您可以编写像常规 XML 文件一样使用它们的代码(例如,如果您想从模式中自动生成代码类)

In addition to having a far richer feature set (like you mention, including data types and namespaces), they are also XML documents themselves, which can be really useful. Because they are XML, you can check their well-formedness and validity a lot easier, and you can write code that works with them like regular XML files (for instance, if you wanted to autogenerate code classes from a schema)

这篇关于如何在 DTD 和 XSD 之间进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 11:18