XML Schema include 元素
定義和用法
include 元素用於向一個文檔添加帶有相同目標命名空間的多個schema。
元素信息
- 父元素: schema
語法
<include
id=ID
schemaLocation=anyURI
any attributes
>
(annotation?)
</include>
id=ID
schemaLocation=anyURI
any attributes
>
(annotation?)
</include>
(? 符號聲明在include 元素中,該元素可出現零次或一次。)
属性 | 描述 |
---|---|
id | 可选。规定该元素的唯一的 ID。 |
schemaLocation | 必需。规定在包含 schema 的目标命名空间中,要包括的 schema 的 URI。 |
any attributes | 可选。规定带有 non-schema 命名空间的任何其他属性。 |
實例1
通過被包括的schema,被包括的文件必須全部引用相同的目標命名空間。 如果schema 目標命名空間不匹配,則包括不會有效:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3cschool.cc/schema">
<xs:include schemaLocation="http://www.w3cschool.cc/schema/customer.xsd"/>
<xs:include schemaLocation="http://www.w3cschool.cc/schema/company.xsd"/>
..
..
..
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3cschool.cc/schema">
<xs:include schemaLocation="http://www.w3cschool.cc/schema/customer.xsd"/>
<xs:include schemaLocation="http://www.w3cschool.cc/schema/company.xsd"/>
..
..
..
</xs:schema>
完整XML Schema參考手冊