xml基础知识(9)
来源:互联网 发布:ipad pro 10.5 知乎 编辑:程序博客网 时间:2024/05/17 03:54
xml文档中可以写什么元素,元素中又可以增加什么属性,这些限定都需要限定文件来给予约束。
所以有必要了解约束文档的写法。
约束文档有两种:DTD、Schema。
Schema可以引入多个约束文档,DTD只能引入一个。
此处讲解Schema的基础知识。
案例:
元素定义:
<xs:element name="lastname" type="xs:string" default="bbb"/>
<xs:element name="age" type="xs:integer" fixed="15"/>
<xs:element name="dateborn" type="xs:date" use="required"/>
对应的xml元素:
<lastname>aaa</lastname>
<age>15</age>
<dateborn>1999-09-09</dateborn>
限定属性:
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">//age只能写入integer类型
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>//限定在0-120之间
<xs:enumeration value="29"/>
<xs:enumeration value="69"/>//限定枚举
</xs:restriction>
</xs:simpleType>
<xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z][A-Z][A-Z]"/>//输入正则表达式约束
</xs:restriction>
</xs:simpleType>
定义复杂元素:
<xs:element name="employee" type="personinfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>//一个元素还有多个子元素可以成为复杂元素
</xs:sequence>
</xs:complexType>
<xs:element name="product" type="prodtype"/>
<xs:complexType name="prodtype">
<xs:attribute name="prodid" type="xs:positiveInteger"/>//属性名称为prodid,属性内容为正整数
</xs:complexType>
指示器:
<xs:element name="person">
<xs:complexType>
<xs:choice>
<xs:element name="employee" type="employee"/>
<xs:element name="member" type="member"/>//两个子元素二选一
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string" maxOccurs="10" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- xml基础知识(9)
- xml基础知识(一)
- xml基础知识(1)
- xml基础知识(2)
- xml基础知识(3)
- xml基础知识(4)
- XML基础知识(5)
- xml基础知识(6)
- xml基础知识(7)
- xml基础知识(8)
- 2011-9-26 Xml基础知识
- xml基础知识
- xml基础知识
- xml基础知识
- XML基础知识
- XML基础知识
- xml基础知识
- XML基础知识
- 1206反例背后的产品观
- shiro注解更改角色权限认证方式,和和或
- Fill UVA
- STC89C52 -- 常用元器件
- TCP层URG、PSH标识
- xml基础知识(9)
- ajax属性的删,修。selected,chaecked,readonly,disabled,noresize。oncilck的另一种写法。自定义创建$()。回车监听事件。追加方法
- javascript原型链
- 程序设计模式(十六) C++ 备忘录( Memento)模式
- BZOJ 1011-遥远的行星(近似计算)
- sklearn中的异常检测方法
- 工厂模式
- UVA 1629 Cake slicing(四维DP)【分割格子类模板】
- 产品团队之矩阵式组织结构