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声明经常写成这样:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="elementFormDefault="qualified">
The following fragment:
看下面的片段:
xmlns:xs="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:
这个片段:
indicates that the elements defined by this schema (note,to,from,heading,body.) come from the "http://www.w3schools.com" namespace.
暗示了由这份schema(note,body.)定义的元素来自"http://www.w3schools.com"名称空间(namespace)
indicates that the default namespace ishttp://www.w3schools.com.
指明了默认名称空间(namespace)是这个片段
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
<note xmlns="xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.comnote.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
下面的片段:
specifies the default namespace declaration. This declaration tells the schema-validator that all the elements used in this XML document are declared in the "指定了默认的名称空间(default namespace)声明。这个声明告诉schema-检验器:这份XML文档里用到的所有元素都在http://www.w3schools.com的名称空间(namespace)中声明过。
Once you have the XML Schema Instance namespace available:
一旦你有了可以利用的XML Schema Instance的名称空间(namespace):
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的位置。
http://www.w3schools.comnote.xsd" 原文链接:https://www.f2er.com/xml/297995.html