最近在公司问了一下,知道schema的人很少,能够运用的更是凤毛麟角.
schema是用来定义xml的,就象定义数据库中库中要定义表结构,没有schma的xml是一盘散沙.
在很多产品中,都能看到schema的身影,比如.net中的dataset,Office中的infopath,WebService中的wsdl...
schema的一些特点:
定义简单和复杂的数据结构
用NameSpace来区别,相互引用
语言无关
可以加入描述等附加信息...
先看看schema的简单功能:
<xs:simpleType name="chineseName">
<xs:restriction base="xs:string">
<xs:maxLength value="5"/>
<xs:minLength value="2"/>
</xs:restriction>
</xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="5"/>
<xs:minLength value="2"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="arenumber">
<xs:restriction base="xs:string">
<xs:pattern value="0[1-9][0-9]{1,2}"/>
</xs:restriction>
</xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="0[1-9][0-9]{1,2}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="gender">
<xs:restriction base="xs:string">
<xs:enumeration value="男"/>
<xs:enumeration value="女"/>
</xs:restriction>
</xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="男"/>
<xs:enumeration value="女"/>
</xs:restriction>
</xs:simpleType>