Schema约束示例

<?xml version="1.0"?>

<!-- 
    targetNamespace:命名空间
 -->
<xsd:schema xmlns="http://www.itcast.cn/xml"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            targetNamespace="http://www.itcast.cn/xml"
            elementForDedault="qualified">
    <xsd:element name="students" type="studentsType" /> <!--根元素为students-->
    <xsd:complexType name="studentsType"> <!--创建复杂类型的时候,需要查看引用的name-->
        <xsd:sequence>
            <xsd:element name="student" type="studentType" minOccurs="0"
                maxOccurs="unbounded" />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="studentType"><!--创建复杂类型的时候,需要查看引用的name-->
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string" />
            <xsd:element name="age" type="ageType" />
            <xsd:element name="sex" type="sexType" />
        </xsd:sequence><!--student类型下的元素-->
        <xsd:attribute name="numberType" type="numberType" use="required"><!--student的属性-->
    </xsd:complexType>

    <xsd:simpleType name="ageType"><!--age元素的具体情况-->
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="0" />
            <xsd:maxInclusive value="120" />
        </xsd:restriction>
    </xsd:simpleType>


    <xsd:simpleType name="numberType"><!--number属性的具体情况-->
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="ITCAST_\d{4}"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="sexType"><!--sex属性的具体情况-->
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="male"/>
            <xsd:enumeration value="female"/>
        </xsd:restriction>
    </xsd:simpleType>

</xsd:schema>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

楚蕊博南谭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值