如何在DTD和XSD之间选择 [英] How to choose between DTD and XSD

查看:74
本文介绍了如何在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之间选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆