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

兩個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/cla***oom" 

xmlns:tns="http://www.example.org/cla***oom" 

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>


cla***oom.xsd

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 

targetNamespace="http://www.example.org/cla***oom" 

xmlns:tns="http://www.example.org/cla***oom" 

elementFormDefault="qualified">

<!-- 兩個文件必須在同一個命名空間下(targetNamespace) -->

<xsd:include schemaLocation="student.xsd"/>

<xsd:element name="cla***oom" type="tns:cla***oomType"/>

<xsd:complexType name="cla***oomType">

<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>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章