XML Schema高级特性
深入学习Schema约束,包括复杂类型、派生和替换组。 · 难度:入门 · +15XP
高级Schema构造
XML Schema提供了丰富的数据类型和约束机制。除了基本类型,还可以定义复杂类型、使用继承和替换组实现灵活性。
复杂类型定义
<xs:complexType name="BookType">
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>类型派生
| 方式 | 说明 |
|---|---|
| 限制(restriction) | 缩小取值范围 |
| 扩展(extension) | 添加新元素或属性 |
替换组
<xs:element name="publication" type="PublicationType"/>
<xs:element name="book" type="BookType" substitutionGroup="publication"/>练习提示
创建一个派生自BookType的EBookType,添加<format>元素和<size>属性。验证实例文档。