微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

XML Schema和DTD有什么区别?

我已经google了这个问题,但我不明白什么是XML模式和DTD(文档类型定义),以及为什么XML模式比DTD更强大。

任何指导将高度赞赏。

Converting a DTD into a SchemaConverting a DTD into a Schema部分:

The critical difference between DTDs
and XML Schema is that XML Schema
utilize an XML-based Syntax,whereas
DTDs have a unique Syntax held over
from SGML DTDs. Although DTDs are
often criticized because of this need
to learn a new Syntax,the Syntax
itself is quite terse. The opposite is
true for XML Schema,which are
verbose,but also make use of tags and
XML so that authors of XML should find
the Syntax of XML Schema less
intimidating.

The goal of DTDs was to retain a level
of compatibility with SGML for
applications that might want to
convert SGML DTDs into XML DTDs.
However,in keeping with one of the
goals of XML,“terseness in XML markup
is of minimal importance,” there is no
real concern with keeping the Syntax
brief.

[…]

So what are some of the other differences which might be especially important when we are converting a DTD? Let’s take a look.

Typing

The most significant difference between DTDs and XML Schema is the capability to create and use datatypes in Schema in conjunction with element and attribute declarations. In fact,it’s such an important difference that one half of the XML Schema Recommendation is deVoted to datatyping and XML Schema. We cover datatypes in detail in Part III of this book,“XML Schema Datatypes.”

[…]

Occurrence Constraints

Another area where DTDs and Schema differ significantly is with occurrence constraints. If you recall from our prevIoUs examples in Chapter 2,“Schema Structure” (or your own work with DTDs),there are three symbols that you can use to limit the number of occurrences of an element: *,+ and ?.

[…]

Enumerations

So,let’s say we had a element,and we wanted to be able to define a size attribute for the shirt,which allowed users to choose a size: small,medium,or large. Our DTD would look like this:

06000

[…]

But what if we wanted size to be an element? We can’t do that with a DTD. DTDs do not provide for enumerations in an element’s text content. However,because of datatypes with Schema,when we declared the enumeration in the preceding example,we actually created a simpleType called size_values which we can Now use with an element:

06001

[…]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类