为何使用 XML Schemas?

XML Schemas are much more powerful than DTDs.
XML Schema比DTD作用更加强大。


XML Schemas Support Data Types
XML Schema支持数据类型

One of the greatest strength of XML Schemas is the support for data types.
XML Schema的最好用的地方之一就是它支持数据类型

With support for data types:
支持数据类型所带来的好处:

  • It is easier to describe allowable document content
    更易于描述被允许的文档内容
  • It is easier to validate the correctness of data
    更易于检验数据的正确性
  • It is easier to work with data from a database
    更易于与数据库中的数据一起协同工作
  • It is easier to define data facets (restrictions on data)
    更易于定义数据的使用面(关于数据的限制)
  • It is easier to define data patterns (data formats)
    更易于定义数据样式(数据格式)
  • It is easier to convert data between different data types
    更易于把数据转换成不同的数据类型

XML Schemas use XML Syntax
XML Schema使用XML的语法

Another great strength about XML Schemas is that they are written in XML.
XML Schema另一个好处就是他们是用XML编写成的。

Some benefits of that XML Schemas are written in XML:
用XML编写的好处是:

  • You don't have to learn a new language
    可以不需要再学一种新语言
  • You can use your XML editor to edit your Schema files
    可以用XML编辑器来编辑Schema文件
  • You can use your XML parser to parse your Schema files
    可以用XML解析器解析Schema文件
  • You can manipulate your Schema with the XML DOM
    可以用XML DOM 处理Schema
  • You can transform your Schema with XSLT
    可以用XSLT转换Schema

XML Schemas Secure Data Communication
XML Schema安全数据通讯

When sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content.
当数据由发送者被传向接受者时,双方对“数据内容理解的一致性”就显得非常重要了

With XML Schemas, the sender can describe the data in a way that the receiver will understand.
在XML Schema里,发送者可以用接受者能够理解的方式描述数据。

A date like: "03-11-2004" will, in some countries, be interpreted as 3.November and in other countries as 11.March.
像这样格式的日期:"03-11-2004",一些国家会解释成11月3日,而别的国家会解释成3月11日

However, an XML element with a data type like this:
<date type="date">2004-03-11</date>
ensures a mutual understanding of the content, because the XML data type "date" requires the format "YYYY-MM-DD".
然而,一个有着像这样的数据种类的XML元素:<date type="date">2004-03-11</date>,就确保了双方都能理解其内容,因为XML数据类型的"date"要求规定为"YYYY-MM-DD"的格式。


XML Schemas are Extensible
XML Schema是可扩展的

XML Schemas are extensible, because they are written in XML.
因为XML Schema文件是由XML编写的,所以它们是可扩展的。

With an extensible Schema definition you can:
Schema可扩展意味着你可以:

  • Reuse your Schema in other Schemas
    在别的Schema文件里再次用到你的Schema
  • Create your own data types derived from the standard types
    从标准的数据类型中派生出你自己的数据类型
  • Reference multiple schemas in the same document
    在相同的文档中参考多种Schema。

Well-Formed is not Enough
光有“规范”仍然是不够的

A well-formed XML document is a document that conforms to the XML syntax rules, like:
规范的XML文档是符合XML语法规则的文档,就像这样:

  • it must begin with the XML declaration
    • 开头必须有XML声明
  • it must have one unique root element
    • 必须有一个独特的根目录元素
  • start-tags must have matching end-tags
    • 开始标签(start-tag)必须和结束标签(end-tag)匹配
  • elements are case sensitive
    • 元素是有大小写区分的
  • all elements must be closed
    • 元素必须有结束
  • all elements must be properly nested
    • 所有的元素必须被合理嵌套
  • all attribute values must be quoted
    • 所有属性值必须写在引号里
  • entities must be used for special characters
    • 用特殊字符时必须用到实体

Even if documents are well-formed they can still contain errors, and those errors can have serious consequences.
即使文档是规范的,它们也可能包含错误。这些错误可能会引起严重的后果。

Think of the following situation: you order 5 gross of laser printers, instead of 5 laser printers. With XML Schemas, most of these errors can be caught by your validating software.
试想下面的情况:你预定了 5罗(1罗=12打=144台)激光打印机,而不是5台打印机。在XML Schema文件里,大多数像这样的错误会由检验软件产生。

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值