XSD – 元素概述

导读 <schema>元素是每一个 XML Schema 的根元素。
<schema> 元素

<sschema> 元素是每一个 XML Schema 的根元素:

<s?xml version="1.0"?>
<sxs:schema>
...
...
<s/xs:schema>

<sschema> 元素可包含属性。一个 schema 声明往往看上去类似这样:

<s?xml version="1.0"?>
<sxs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.runoob.com"
xmlns="http://www.runoob.com"
elementFormDefault="qualified">
...
...
<s/xs:schema>

以下代码片段:

xmlns:xs="http://www.w3.org/2001/XMLSchema"

显示 schema 中用到的元素和数据类型来自命名空间 “http://www.w3.org/2001/XMLSchema”。同时它还规定了来自命名空间 “http://www.w3.org/2001/XMLSchema” 的元素和数据类型应该使用前缀 xs:

这个片断:

targetNamespace="http://www.runoob.com"

显示被此 schema 定义的元素 (note, to, from, heading, body) 来自命名空间: “http://www.runoob.com”。

这个片断:

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

指出默认的命名空间是 “http://www.runoob.com”。

这个片断:

elementFormDefault="qualified"

指出任何 XML 实例文档所使用的且在此 schema 中声明过的元素必须被命名空间限定。

在 XML 文档中引用 Schema

此 XML 文档含有对 XML Schema 的引用:

<s?xml version="1.0"?>
<snote xmlns="http://www.runoob.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.runoob.com note.xsd">

<sto>Tove<s/to>
<sfrom>Jani<s/from>
<sheading>Reminder<s/heading>
<sbody>Don't forget me this weekend!<s/body>
<s/note>

下面的代码片断:

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

规定了默认命名空间的声明。此声明会告知 schema 验证器,在此 XML 文档中使用的所有元素都被声明于 “http://www.runoob.com” 这个命名空间。

一旦您拥有了可用的 XML Schema 实例命名空间:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

您就可以使用 schemaLocation 属性了。此属性有两个值。第一个值是需要使用的命名空间。第二个值是供命名空间使用的 XML schema 的位置:

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

原文来自:https://www.runoob.com/schema/schema-schema.html

本文地址:https://www.linuxprobe.com/schema-element-overview.html编辑:王艳敏,审核员:逄增宝

Linux命令大全:https://www.linuxcool.com/

Linux系统大全:https://www.linuxdown.com/

红帽认证RHCE考试心得:https://www.rhce.net/

© 版权声明
THE END
喜欢就支持一下吧