当前位置: 首页 > 网络学院 > XML相关教程 > Schema (XSD) > 为何使用 XML Schemas?
XML Schemas are much more powerful than DTDs.
XML Schema比DTD功能更加强大。
One of the greatest strength of XML Schemas is the support for data types.
XML Schema的最强大的功能之一就是它支持数据类型。
With support for data types:
支持数据类型的好处:
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的好处是:
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, because they are written in XML.
因为XML Schema文件是由XML编写的,所以它们是可扩展的。
With an extensible Schema definition you can:
Schema的扩展性可以包含下述定义:
A well-formed XML document is a document that conforms to the XML syntax rules, like:
规范的XML文档是符合XML语法规则的文档,具体如下:
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文件里,大多数类似这样的错误会由检验软件产生。