设计一个通讯录的XML文件

设计一个通讯录的XML文件,要求用模式文档进行以下约束 
1)姓名标记至少出现1次,最多出现200次
2)姓名标记下必须顺序的出现:出生日期,性别,年龄,手机号码,邮件地址
3)年龄必须是非负整数
4)出生日期必须满足日期的格式

xml  schema

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="通讯录">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="姓名" maxOccurs="200"/>
                <xs:element name="出生日期">
                    <xs:simpleType>
                        <xs:restriction base="xs:date"/>
                    </xs:simpleType>
                </xs:element>
                <xs:element name="性别">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="男"/>
                            <xs:enumeration value="女"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
                <xs:element name="年龄">
                    <xs:simpleType>
                        <xs:restriction base="xs:integer">
                            <xs:minExclusive value="0"/>
                            <xs:maxExclusive value="100"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
                <xs:element name="手机号码">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:length value="11"/>
                            <xs:pattern value="[0-9]*"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
                <xs:element name="邮件地址">
                    <xs:simpleType>
                        <xs:restriction base="xs:string"/>
                    </xs:simpleType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

xml 代码

<?xml version="1.0" encoding="UTF-8"?>
<通讯录 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="通讯录.xsd">
    <姓名>sdf</姓名>
    <出生日期>1998-01-01</出生日期>
    <性别>女</性别>
    <年龄>14</年龄>
    <手机号码>13697788344</手机号码>
    <邮件地址/>
</通讯录>


 

猜你喜欢

转载自blog.csdn.net/thomassamul/article/details/81108059