加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xsd – DTD或XML模式 哪一个更好?

发布时间:2020-12-16 01:53:50 所属栏目:百科 来源:网络整理
导读:什么是DTD和XML模式的优点/缺点(我甚至不知道后者的官方名称是什么!)?哪个更好?为什么我们需要两种方法来做同样的事情? 编辑:我发现这在一篇文章,我正在读,这是什么促使我问的问题: Why W3C XML Schema Language? The W3C XML Schema Language is no
什么是DTD和XML模式的优点/缺点(我甚至不知道后者的官方名称是什么!)?哪个更好?为什么我们需要两种方法来做同样的事情?

编辑:我发现这在一篇文章,我正在读,这是什么促使我问的问题:

Why W3C XML Schema Language?

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. 07000

我想我想要的例子说明为什么XML-Schema更好(如果它确实是)。

从 http://weblogs.asp.net/rchartier/archive/2006/03/21/440782.aspx
  • DTD’s are not namespace aware.

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

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

  • XSD has a type system.

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

  • You can put a DTD inline into an XML document,you cannot do this with XSD. This means DTD’s are more secure (you only
    have to protect one bytestream — the xml/dtd — and not
    multiple).

  • 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,虽然我确定它存在。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读