跳转到内容

XML Schema

维基百科,自由的百科全书

这是本页的一个历史版本,由Zanhsieh留言 | 贡献2006年4月30日 (日) 19:27编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)

XML Schema, published as a W3C Recommendation in May 2001, is one of several XML schema languages. It was the first separate schema language for XML to achieve Recommendation status by the W3C.

Like all XML schema languages, XML Schema can be used to express a schema: a set of rules to which an XML document must conform in order to be considered 'valid' according to that schema. However, unlike most other schema languages, XML Schema was also designed with the intent of validation resulting in a collection of information adhering to specific datatypes, which can be useful in the development of XML document processing software, but which has also provoked criticism.

Citation

Since other XML schema languages exist, it is important to cite the W3C-recommended language as either XML Schema or W3C XML Schema, always with the word Schema capitalized.

An XML Schema instance is an XML Schema Definition (XSD) and typically has the filename extension ".xsd". The language itself is sometimes informally referenced as XSD, even though WXS (for W3C XML Schema) is the more appropriate initialism.

History

In its appendix of references, XML Schema acknowledges the influence of DTD and other early XML schema efforts such as DDML, SOX, XML-Data, and XDR. It appears to have picked pieces from each of these proposals, but is also a compromise between them. Of those languages, XDR and SOX continued to be used and supported for a while after XML Schema was published. A number of Microsoft products supported XDR until the release of MSXML 4.0 (which dropped XDR in favor of XML Schema) in October 2001. Commerce One, Inc. supported its SOX schema language until declaring bankruptcy in late 2004. In December of that year, Novell, Inc. purchased the company's patents, including those related to SOX, reportedly in an effort to keep them from being exploited by unrelated companies whose primary business is filing patent-related lawsuits.[1]

Post-Schema-Validation Infoset

After XML Schema-based validation, it is possible to express an XML document's structure and content in terms of the data model that was implicit during validation. The XML Schema data model includes:

  • the vocabulary (element and attribute names)
  • the content model (relationships and structure)
  • and data types.

This collection of information is called the Post-Schema-Validation Infoset (PSVI). The PSVI gives a valid XML document its "type" and facilitates treating the document as an object, using object-oriented programming (OOP) paradigms.

This particular OOP approach to XML data access was primarily advocated by Microsoft, a major contributor to the development of XML Schema. Converting an XML document to a datatype-aware object can be beneficial in some parts of computer software design, but critics contend that it also undermines openness, a key feature of XML, and that it is biased toward compatibility with the datatypes native to Microsoft's favored programming languages.[2]

In addition, the limitations inherent to (and caused by) XML Schema datatypes, the restrictive coupling of those datatypes with the rest of XML Schema, and dependencies on those datatypes in other W3C specifications are points of contention among a number of XML software developers.[3]

Example

An example of a very simple Schema to describe a country is given below.

<xs:schema
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element name="country" type="Country"/>
 <xs:complexType name="Country">
  <xs:sequence>
   <xs:element name="name" type="xs:string"/>
   <xs:element name="population" type="xs:decimal"/>
  </xs:sequence>
 </xs:complexType>
</xs:schema>

An example of an XML document that conforms to this schema is given below.

<country
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="country.xsd">
  <name>France</name>
  <population>59.7</population>
</country>

See also

  • RELAX NG - another XML schema language (an ISO international standard) that is often used with XML Schema datatypes