当前位置: 首页 > 网络学院 > XML相关教程 > Schema (XSD) > 为何使用 XML Schemas?

Schema (XSD)
XSD 逻辑值数据类型
XML Schema总结
XML Schema 参考
XSD 验证

Schema (XSD) 中的 为何使用 XML Schemas?


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 943 ::
收藏到网摘: n/a

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编写XML Schema的好处是:

  • 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
    起始标签必须和结束标签匹配
  • 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文件里,大多数类似这样的错误会由检验软件产生。

评论 (0) All

登陆 | 还没注册?