DTD 或 XML 模式.哪一个更好? [英] DTD or XML Schema. Which one is better?

查看:23
本文介绍了DTD 或 XML 模式.哪一个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DTD 和 XML 模式的优缺点是什么(我什至不确定后者的正式名称是什么!)?哪个更好?为什么我们需要两种方法来做同样的事情?

What are the pros / cons in DTD and XML Schemas (I'm not even sure what the official name of the latter is!)? Which is better? Why do we need two ways to do the same thing?

我在正在阅读的一篇文章中发现了这一点,这促使我提出了这个问题:

I found this in an article I was reading, which is what prompted me to ask the question:

为什么选择 W3C XML 模式语言?

Why W3C XML Schema Language?

W3C XML 模式语言不是只有模式语言.事实上,XML规范描述文档类型定义(DTD)作为方法表达一个模式.此外,JAXB 的预发布版本参考实现只工作使用 DTD——也就是说,不使用模式用 XML 模式语言编写.但是,XML 模式语言是比 DTD 丰富得多.例如,用 XML Schema 编写的模式语言可以描述结构关系和数据类型不能表达(或不能轻易表达表示)在 DTD 中.有工具可用于将 DTD 转换为 W3CXML Schema Language,所以如果你有您使用的基于 DTD 的模式JAXB 的早期版本参考实现,可以使用这些工具将模式转换为XML 模式语言.http://java.sun.com/developer/technicalArticles/WebServices/jaxb/#binsch

The W3C XML Schema Language is not the only schema language. In fact, the XML specification describes document-type definitions (DTDs) as the way to express a schema. In addition, pre-release versions of the JAXB Reference Implementation worked only with DTDs -- that is, not with schemas written in the XML Schema Language. However, the XML Schema Language is much richer than DTDs. For example, schemas written in the XML Schema Language can describe structural relationships and data types that can't be expressed (or can't easily be expressed) in DTDs. There are tools available to convert DTDs to the W3C XML Schema Language, so if you have DTD-based schemas that you used with an earlier version of the JAXB Reference Implementation, you can use these tools to convert the schemas to XML Schema Language. http://java.sun.com/developer/technicalArticles/WebServices/jaxb/#binsch

我想我想要一些例子来说明为什么 XML-Schema 更好(如果确实如此的话).

I guess I would like examples that illustrate why XML-Schema is better (if it indeed is).

推荐答案

来自 http://weblogs.asp.net/rchartier/archive/2006/03/21/440782.aspx

  • DTD 不支持命名空间.

  • DTD's are not namespace aware.

DTD 有 #define#include#ifdef -- 或者,较少面向 C 语言,能够定义速记缩写,外部内容,以及一些条件解析.

DTD's have #define, #include, and #ifdef -- or, less C-oriented, the ability to define shorthand abbreviations, external content, and some conditional parsing.

DTD 描述了整个 XML 文档(即使它留下了漏洞");架构可以定义部分.

A DTD describes the entire XML document (even if it leaves "holes"); a schema can define portions.

XSD 有一个类型系统.

XSD has a type system.

XSD 有更丰富的语言来描述元素或属性内容的外观".这与类型有关系统.

XSD has a much richer language for describing what element or attribute content "looks like." This is related to the type system.

您可以将 DTD 内联到 XML 文档中,而 XSD 无法做到这一点.这意味着 DTD 更安全(您只需必须保护一个字节流——xml/dtd——而不是
多个).

有效 XML"的官方定义需要一个 DTD.由于这可能是不切实际的,如果不是不可能的话,你经常不得不满足于 schema-valid,这并不完全相同.

The official definition of "valid XML" requires a DTD. Since this may be impractical, if not impossible, you often have to settle for schema-valid, which is not quite the same.

就我而言,如果您有 XSD,那么为某些 XML 编写验证器非常简单.虽然我确信它存在,但我还没有看到它与 DTD 一起使用.

For my part, it's pretty straightforward to write a validator for some XML if you have an XSD. I haven't seen this with a DTD, although I'm sure it exists.

这篇关于DTD 或 XML 模式.哪一个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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