加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

XML(4)——schema文件相互引用

发布时间:2020-12-16 09:43:41 所属栏目:百科 来源:网络整理
导读:两个xsd必须在同一命名空间下targetNamespace。 student.xsd ?xml version="1.0" encoding="UTF-8"? xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/classroom" xmlns:tns="http://www.example.org/clas
两个xsd必须在同一命名空间下targetNamespace。

student.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/classroom"
xmlns:tns="http://www.example.org/classroom"
elementFormDefault="qualified">
<xsd:element name="student" type="tns:studentType"/>

<xsd:complexType name="studentType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="sex" type="tns:sexType"/>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="sexType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="男"/>
<xsd:enumeration value="女"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

classroom.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/classroom"
xmlns:tns="http://www.example.org/classroom"
elementFormDefault="qualified">

<!-- 两个文件必须在同一个命名空间下(targetNamespace) -->
<xsd:include schemaLocation="student.xsd"/>

<xsd:element name="classroom" type="tns:classroomType"/>

<xsd:complexType name="classroomType">
<xsd:sequence>
<xsd:element name="grade" type="tns:gradeType"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:sequence minOccurs="1" maxOccurs="unbounded">
<xsd:element name="student" type="tns:studentType"/> </xsd:sequence> </xsd:sequence> </xsd:complexType> <xsd:simpleType name="gradeType"> <xsd:restriction base="xsd:int"> <xsd:minInclusive value="2000"/> <xsd:maxInclusive value="3000"/> </xsd:restriction> </xsd:simpleType> </xsd:schema>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读