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

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

问题描述

DTD和XML Schema中有什么优点/缺点(我什至不确定后者的正式名称是什么!)?哪个更好?为什么我们需要两种方法来完成相同的工作?

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 Schema语言编写的
模式无效。
但是,XML Schema语言比DTD丰富得多。例如,以XML模式
语言编写的
模式可以描述
无法表达(或不能轻易成为
的结构化
关系和数据类型)在DTD中表示)。有可用的工具
可以将DTD转换为W3C
XML模式语言,因此,如果您有与
一起使用的
基于DTD的模式,则JAXB $ b的早期版本$ b参考实现,您可以使用
这些工具将架构转换为
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。由于这可能是不切实际的,即使不是不可能的,您也经常需要
来解决架构有效的问题,这并不完全相同。

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天全站免登陆