Why Schema

Why Scheme?和DTD功能一样
DTD语法怪异,SCML的残留
DTD没有数据类型
没有对DTD的编程接口
Schema简单,本身就是XML,克服了以上的缺点


实例1:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="quantity" type="nonNegativeInteger">
    <!--nonNegativeInteger代表的就是非负数-->
    </xs:element>

<quantity>5</quantity>可以
<quantity>-13</quantity>不可以



实例2:
<?xml version="1.0" encoding="gb2312"?>
<xs:schema xmlna:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="丛书">
       <xs:complexType>
         <xs:sequence>
           <xs:element name="书">
         <xs:element name="名" minoccurs="1"></xs:element>
         <xs:element name="人"></xs:element>
         <xs:element name="价">
            <xs:attribute name="unit">
                <xs:attribute value="RMB"/>
                <xs:attribute value="美元"/>
                <xs:attribute value="日元"/>
            </xs:attribute>
         </xs:element>
           </xs:element>
          </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>


注意:
minoccurs="1"代表至少出现一次
<xs:attribute name="unit">代表枚举类型
           

猜你喜欢

转载自1124117571.iteye.com/blog/2289817
Why