编写A.xsd文件
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="www.a.com/stu" xmlns:Aid="www.a.com/stu" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="id" type="Aid:idt"/>
<xs:simpleType name="idt">
<xs:restriction base="xs:string">
<xs:length value="7"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
设置targetNamespace为www.a.com/stu,因为后面需要引用,所以此处需要设置xmlns:Aid=“www.a.com/stu”
编写B.xsd文件
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:prd="www.a.com/stu" targetNamespace="www.a.com/stu" >
<xs:include schemaLocation="A.xsd"/>
<xs:element name="stu" type="prd:stutype"/>
<xs:complexType name="stutype">
<xs:sequence>
<xs:element name="id" type="prd:idt"></xs:element>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="age" type="xs:integer"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
这里的代码段使用了include,由于A和B在同一个targetNamespace下面,所以可以使用include,<xs:include schemaLocation=“A.xsd”/>
<xs:element name=“id” type=“prd:idt”></xs:element>为对A的引用,和A出现的情况一样,由于想在此xsd中写element,所以需要给此文件起别名
编写C.xsd文件
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="www.a.com/student" xmlns:prd="www.a.com/stu" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="www.a.com/stu" schemaLocation="B.xsd"/>
<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element name="stu" type="prd:stutype" maxOccurs="1000"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
这里的代码段使用了import,由于C和B在不在同一个targetNamespace下面,所以可以使用import,
**<xs:import namespace=“www.a.com/stu” schemaLocation=“b.xsd”/>**对B的引用