XSD的学习

一 基础概念

schema:root element of each xml schema.and contain several attributes.like xmlns:xs,targetNameSpace,xmlns,elementFormDefault.
element:it have single element and complext element.And the element type can be string,decimal,integer,boolean,date,time.
attribute:used in the element.like element,it can use many types.
restrictions:<xs:restriction>,<xs:minInclusive>,<xs:maxInclusive>,<xs:simpleType>,<xs:pattern>
simpleType:element,attribute,restriction.
group:a group element.
attributeGroup:a set of attribute declarations.
choice:allow only one element contained in the <choice> declaration.
complexType:a complexType is an XML element that contains other elements or attributes.
union:defines a simple type as a collection (union) of values from specified simple data types
unique:an element or an attribute value must be unique within the scope.
sequence:the child elements must appear in a sequence

二:具体的XSD

<xs:schema xmlns:xs="">

<xs:group name="custGroup">
<xs:sequence>
<xs:element name="customer" type="xs:string"/>
<xs:element name="orderdetails" type="xs:string"/>
<xs:element name="billto" type="xs:string"/>
<xs:element name="shipto" type="xs:string"/>
</xs:sequence>
</xs:group>


<xs:element name="name" type="xs:string" default="Zhangsan>
<xs:attribute name="sex" type="xs:string" default="male" use="required"></xs:attribute>

</xs:element>

<xs:element name="age" type="xs:integer">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction>
</xs:simpleType>
<xs:element>

<xs:complexType name="ordertype">
<xs:group ref="custGroup"/>
<xs:attribute name="status" type="xs:string"/>
</xs:complexType>

<xs:attributeGroup name="personattr">
<xs:attribute name="attr1" type="string"/>
<xs:attribute name="attr2" type="integer"/>
</xs:attributeGroup>

<xs:complexType name="person">
<xs:attributeGroup ref="personattr"/>
</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="jeans_size">
<xs:simpleType>
<xs:union memberTypes="sizebyno sizebystring" />
</xs:simpleType>
</xs:element>

<xs:simpleType name="sizebyno">
<xs:restriction base="xs:positiveInteger">
<xs:maxInclusive value="42"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="sizebystring">
<xs:restriction base="xs:string">
<xs:enumeration value="small"/>
<xs:enumeration value="medium"/>
<xs:enumeration value="large"/>
</xs:restriction>
</xs:simpleType>

<xs:unique name="IDUnique">
<xs:selector xpath="学生"/>
<xs:field xpath="@学号"/>
</xs:unique>

<xs:element name="personinfo">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

转载于:https://www.cnblogs.com/SoulSpirit/archive/2013/02/27/2935609.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值