<!--schema复合元素-->
案例1
<?@H_404_17@xmlversion@H_502_21@="1.0"encoding@H_502_21@="UTF-8"?>
<@H_404_17@xs:schemaxmlns:xs@H_502_21@="http://www.w3.org/2001/XMLSchema"
targetNamespace@H_502_21@="http://www.csdn.net"
elementFormDefault@H_502_21@="qualified">
<@H_404_17@xs:elementname@H_502_21@="books">
<!--复合元素-->
<@H_404_17@xs:complexType>
<@H_404_17@xs:sequence>
<!--子元素-->
<@H_404_17@xs:elementname@H_502_21@="book">
<@H_404_17@xs:complexType>
<!--定义了一个属性-->
<@H_404_17@xs:attributename@H_502_21@="isbn"type@H_502_21@="xs:string"use@H_502_21@="required"/>
</@H_404_17@xs:complexType>
</@H_404_17@xs:element>
</@H_404_17@xs:sequence>
<@H_404_17@xs:attributename@H_502_21@="defaultDemo"type@H_502_21@="xs:string"use@H_502_21@="required"/>
</@H_404_17@xs:complexType>
</@H_404_17@xs:element>
</@H_404_17@xs:schema>
被约束文件
<?@H_404_17@xmlversion@H_502_21@="1.0"encoding@H_502_21@="UTF-8"?>
<@H_404_17@booksxmlns@H_502_21@="http://www.csdn.net"
xmlns:xsi@H_502_21@="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation@H_502_21@="http://www.csdn.netempl.xsd"
defaultDemo@H_502_21@="yy">
<@H_404_17@bookisbn@H_502_21@="00xx1"></@H_404_17@book>
</@H_404_17@books>
案例2
<?@H_404_17@xmlversion@H_502_21@="1.0"encoding@H_502_21@="UTF-8"?>
<@H_404_17@xs:schemaxmlns:xs@H_502_21@="http://www.w3.org/2001/XMLSchema"
targetNamespace@H_502_21@="http://www.example.org/fh"
elementFormDefault@H_502_21@="qualified">
@H_502_21@<@H_404_17@xs:elementname@H_502_21@="employee">
@H_502_21@<@H_404_17@xs:complexType>
@H_502_21@<@H_404_17@xs:sequence>
@H_502_21@<@H_404_17@xs:elementname@H_502_21@="firstname"type@H_502_21@="xs:string"/>
@H_502_21@<@H_404_17@xs:elementname@H_502_21@="lastname"type@H_502_21@="xs:string"/>
@H_502_21@</@H_404_17@xs:sequence>
@H_502_21@</@H_404_17@xs:complexType>
@H_502_21@
@H_502_21@</@H_404_17@xs:element>
</@H_404_17@xs:schema>
被约束文件
<?@H_404_17@xmlversion@H_502_21@="1.0"encoding@H_502_21@="UTF-8"?>
<@H_404_17@employeexmlns@H_502_21@="http://www.example.org/fh"
xmlns:xsi@H_502_21@="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation@H_502_21@="http://www.example.org/fhfh.xsd">
<@H_404_17@firstname>@H_502_21@John</@H_404_17@firstname>
<@H_404_17@lastname>@H_502_21@Smith</@H_404_17@lastname>
</@H_404_17@employee>
案例3<定义元素扩展类型>
<?@H_404_17@xmlversion@H_502_21@="1.0"encoding@H_502_21@="UTF-8"?>
<@H_404_17@xs:schemaxmlns:xs@H_502_21@="http://www.w3.org/2001/XMLSchema"
targetNamespace@H_502_21@="http://www.example.org/fh"xmlns@H_502_21@="http://www.example.org/fh"
elementFormDefault@H_502_21@="qualified">
<@H_404_17@xs:elementname@H_502_21@="users">
<@H_404_17@xs:complexType>
<@H_404_17@xs:sequence>
<!--定义元素-->
<@H_404_17@xs:elementname@H_502_21@="employee"type@H_502_21@="nameType"/>
<!--定义元素-->
<@H_404_17@xs:elementname@H_502_21@="student"type@H_502_21@="nameType"/>
<!--定义元素-->
<@H_404_17@xs:elementname@H_502_21@="teacher"type@H_502_21@="teacherType"/>
</@H_404_17@xs:sequence>
</@H_404_17@xs:complexType>
</@H_404_17@xs:element>
<!--自定义类型-->
<@H_404_17@xs:complexTypename@H_502_21@="nameType">
<@H_404_17@xs:sequence>
<@H_404_17@xs:elementname@H_502_21@="firstname"type@H_502_21@="xs:string"/>
<@H_404_17@xs:elementname@H_502_21@="lastname"type@H_502_21@="xs:string"/>
</@H_404_17@xs:sequence>
</@H_404_17@xs:complexType>
<!--自定义类型-->
<@H_404_17@xs:complexTypename@H_502_21@="teacherType">
<@H_404_17@xs:complexContent>
<!--扩展类型-->
<@H_404_17@xs:extensionbase@H_502_21@="nameType">
<@H_404_17@xs:sequence>
<@H_404_17@xs:elementname@H_502_21@="address"type@H_502_21@="xs:string"/>
<@H_404_17@xs:elementname@H_502_21@="age"type@H_502_21@="xs:integer"/>
</@H_404_17@xs:sequence>
</@H_404_17@xs:extension>
</@H_404_17@xs:complexContent>
</@H_404_17@xs:complexType>
</@H_404_17@xs:schema>
被约束文件
<?@H_404_17@xmlversion@H_502_21@="1.0"encoding@H_502_21@="UTF-8"?>
<@H_404_17@usersxmlns@H_502_21@="http://www.example.org/fh"xmlns:xsi@H_502_21@="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation@H_502_21@="http://www.example.org/fhfh1.xsd">
<@H_404_17@employee>
<@H_404_17@firstname>@H_502_21@John</@H_404_17@firstname>
<@H_404_17@lastname>@H_502_21@Smith</@H_404_17@lastname>
</@H_404_17@employee>
<@H_404_17@student>
<@H_404_17@firstname>@H_502_21@John</@H_404_17@firstname>
<@H_404_17@lastname>@H_502_21@Smith</@H_404_17@lastname>
</@H_404_17@student>
<@H_404_17@teacher>
<@H_404_17@firstname>@H_502_21@John</@H_404_17@firstname>
<@H_404_17@lastname>@H_502_21@Smith</@H_404_17@lastname>
<@H_404_17@address>@H_502_21@河北@H_502_21@石家庄</@H_404_17@address>
<@H_404_17@age>@H_502_21@29</@H_404_17@age>
</@H_404_17@teacher>
</@H_404_17@users>