xml schema 初步

     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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值