加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml schema 初步

发布时间:2020-12-16 05:17:08 所属栏目:百科 来源:网络整理
导读:dtd固然有其进步之处,但还是存在其局限性。随着计算机技术的发展,一种新的xml验证机制随之诞生-----xml schemal,它解决了dtd许多不如人意的地方。 如: xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.person.skydr

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读