The <schema> element is the root element of every XML Schema.
<schema>元素是每个XML Schema文件的根元素。
The <schema> Element
<schema>元素
The <schema> element is the root element of every XML Schema:
<schema>元素是每份XML Schema文件的根元素。
<?xml version="1.0"?> <xs:schema> ... ... </xs:schema> |
The <schema> element may contain some attributes. A schema declaration often looks something like this:
<schema>元素也可以含有一些属性,一个schema声明经常写成这样:
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com" elementFormDefault="qualified"> ... ... </xs:schema> |
The following fragment:
看下面的片段:
xmlns:xs="http://www.w3.org/2001/XMLSchema" |
indicates that the elements and data types used in the schema come from the "http://www.w3.org/2001/XMLSchema" namespace. It also specifies that the elements and data types that come from the "http://www.w3.org/2001/XMLSchema" namespace should be prefixed with xs:
指明了在schema中使用的元素和数据种类来自http://www.w3.org/2001/XMLSchema名称空间(namespace)。它也指定了来自"http://www.w3.org/2001/XMLSchema"名称空间(namespace)的元素和数据种类必须带前缀“xs:”
This fragment:
这个片段:
targetNamespace="http://www.w3schools.com" |
indicates that the elements defined by this schema (note, to, from, heading, body.) come from the "http://www.w3schools.com" namespace.
暗示了由这份schema(note, to, from, heading, body.)定义的元素来自"http://www.w3schools.com"名称空间(namespace)
This fragment:
这个片段:
xmlns="http://www.w3schools.com" |
indicates that the default namespace is http://www.w3schools.com.
指明了默认名称空间(namespace)是http://www.w3schools.com.
This fragment:
这个片段
elementFormDefault="qualified" |
indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.
指明了由这份schema声明的XML实例文档里用到的任何元素,都必须是有效的名称空间(namespace qualified)。
Referencing a Schema in an XML Document
在一份XML文档里提到Schema
This XML document has a reference to an XML Schema:
一份XML文档里提提到XML Schiema
<?xml version="1.0"?> <note xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com note.xsd"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> |
The following fragment:
下面的片段:
xmlns="http://www.w3schools.com" |
specifies the default namespace declaration. This declaration tells the schema-validator that all the elements used in this XML document are declared in the "http://www.w3schools.com" namespace.
指定了默认的名称空间(default namespace)声明。这个声明告诉schema-检验器:这份XML文档里用到的所有元素都在http://www.w3schools.com的名称空间(namespace)中声明过。
Once you have the XML Schema Instance namespace available:
一旦你有了可以利用的XML Schema Instance的名称空间(namespace):
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
you can use the schemaLocation attribute. This attribute has two values. The first value is the namespace to use. The second value is the location of the XML schema to use for that namespace:
你可以用到SchemaLocation属性。这个属性有两个值。第一个值是要用到的名称空间(namespace)。第二个值是为名称空间(namespace)指定了需要使用的XML schema的位置。
xsi:schemaLocation="http://www.w3schools.com note.xsd" |