dtd固然有其进步之处,但还是存在其局限性。随着计算机技术的发展,一种新的xml验证机制随之诞生-----xml schemal,它解决了dtd许多不如人意的地方。
如:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.person.skydream.com"
xmlns="http://www.person.skydream.com"
>
<xs:element name="tools" type="toolsInfo"/>
<xs:complexType name="toolsInfo">
<xs:all>
<xs:element name="book" type="xs:string" default="Spring in Action" minOccurs="0" maxOccurs="10">
<xs:complexType>
<xs:attribute name="price" type="xs:integer" default="30" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.person.skydream.com"
xmlns="http://www.person.skydream.com"
>
xmlns:xs:提供了本文档使用的xml 标签定义uri
targetNamespace与xmlns 指明本文档定义的scheml的uri
<xs:element name="tools" type="toolsInfo"/>
定义了一个tools元素,其具体定义指向toolsInfo
<xs:complexType name="toolsInfo">
<xs:all>
<xs:element name="book" type="xs:string" default="Spring in Action" minOccurs="0" maxOccurs="10">
<xs:complexType>
<xs:attribute name="price" type="xs:integer" default="30" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
复杂元素
default:默认值
type:类型
minOccurs:最小个数
<xs:attribute> 定义元素的属性
<xs:simpleType>定义袁术的取值限定范围
详细内容参考:http://www.w3school.com.cn/schema/schema_dtypes_numeric.asp