当前位置: 首页 > 网络学院 > XML相关教程 > Schema (XSD) > XSD - <schema>元素

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

Schema (XSD) 中的 XSD - <schema>元素


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

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.ruanchen.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”命名空间。它也指定了来自于"http://www.w3.org/2001/XMLSchema"命名空间的元素和数据类型必须附带前缀“xs:”。

This fragment:
该片段如下:

targetNamespace="http://www.ruanchen.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.ruanchen.com"命名空间。

This fragment:
该片段如下:

xmlns="http://www.ruanchen.com"

indicates that the default namespace is http://www.ruanchen.com.
上述案例指明了:默认命名空间是http://www.ruanchen.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实例文档中所使用的所有元素都必须是有效的命名空间。


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.
上述案例指定了:默认的命名空间声明。该声明告诉schema检验器下述信息:这份XML文档中使用的所有元素都在http://www.ruanchen.com的命名空间中声明过。

Once you have the XML Schema Instance namespace available:
现在,你已经拥有了可以使用的XML Schema案例命名空间,具体如下:

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属性。这个属性包含两个值:第一个值表示需要使用的命名空间;第二个值表示为命名空间指定了其在XML schema中的具体位置:

xsi:schemaLocation="http://www.w3schools.com note.xsd"

评论 (0) All

登陆 | 还没注册?