Schema

<?xml version="1.0"?>
<!--schema文档本身就是一个xml文档-->
<xsd:schema xmlns="http://www.itcast.cn/xml"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.itcast.cn/xml" elementFormDefault="qualified">

    <!--element元素-->
    <xsd:element name="students" type="studentsType"/><!--定义标签 名称="students" 类型="studentsType(自定义类型)"-->
    <!--studentsType类型是自定义的,需要声明-->
    <xsd:complexType name="studentsType"><!--声明自定义的类型studentsType-->
        <xsd:sequence> <!--表示按顺序出现元素-->
            <xsd:element name="student" type="studentType" minOccurs="0" maxOccurs="unbounded"/>
            <!--定义(元素)标签 名称="student" 类型="studentType"最小出现="0次" 最大出现="没有绑定(随便)"-->
        </xsd:sequence>
    </xsd:complexType>

    <!--studentType类型是自定义的,需要声明-->
    <xsd:complexType name="studentType"><!--复合类型 名称="studentType"-->
        <xsd:sequence><!--表示按顺序出现元素-->
            <xsd:element name="name" type="xsd:string"/><!--定义(元素)标签名称 名称="name" 类型="xsd:string(字符串类型)"-->
            <xsd:element name="age" type="ageType" /><!--定义(元素)标签名称 名称="age" 类型="ageType(自定义类型)"-->
            <xsd:element name="sex" type="sexType" /><!--定义(元素)标签名称 名称="sex" 类型="sexType(自定义类型)"-->
        </xsd:sequence>
        <!--attribute属性 required必须的-->
        <xsd:attribute name="number" type="numberType" use="required"/>
        <!--定义一个属性 名称="number" 类型="numberType(自定义类型)" use="必须的"-->
    </xsd:complexType>

    <!--ageType类型是自定义的,需要声明-->
    <xsd:simpleType name="ageType"><!--简单类型 名称="ageType"-->
        <!--restriction格式 base基础成分-->
        <xsd:restriction base="xsd:integer"><!--格式 基础成分="数字"-->
            <xsd:minInclusive value="0"/><!--最小值-->
            <xsd:maxInclusive value="256"/><!--最大值-->
        </xsd:restriction>
    </xsd:simpleType>

    <!--sexType类型是自定义的,需要声明-->
    <xsd:simpleType name="sexType"><!--简单类型 名称="sexType"-->
        <xsd:restriction base="xsd:string"><!--格式 基础成分="字符串"-->
            <!--enumeration枚举、列举-->
            <xsd:enumeration value="male"/><!---->
            <xsd:enumeration value="female"/><!---->
        </xsd:restriction>
    </xsd:simpleType>

    <!--numberType类型是自定义的,需要声明-->
    <xsd:simpleType name="numberType"><!--简单类型 名称="numberType"-->
        <xsd:restriction base="xsd:string"><!--格式 基础成分="字符串"-->
            <!--pattern模式、样品-->
            <xsd:pattern value="heima_d{4}"/><!--格式为heima_+数字 4位-->
        </xsd:restriction>
    </xsd:simpleType>
</xsd:schema> 
原文地址:https://www.cnblogs.com/rijiyuelei/p/12404830.html