标签:style blog http io color 使用 sp for on
1 <?xml version="1.0" encoding="UTF-8"?> 2 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> 3 <!-- 全局声明自定义的简单类型gender_type --> 4 <xs:simpleType name="gender_type"> <!-- 简单类型,名字为gender_type, 就像是定义了一个对象, 以后可以直接使用这个gender_type --> 5 <xs:restriction base="xs:token"> <!-- xs 是w3里面定义好了的, xs:token 类似于 xs:string--> 6 <xs:enumeration value="男"/> <!-- enumeration 是枚举类型, 男和女只能选一个 --> 7 <xs:enumeration value="女"/> 8 </xs:restriction> 9 </xs:simpleType> 10 11 12 <!--全局声明自定义的简单类型age_type --> 13 <xs:simpleType name="age_type"> 14 <xs:restriction base="xs:int"> <!-- int 不可以有length --> 15 <xs:maxExclusive value="200"/> <!-- 最大值 --> 16 <xs:minInclusive value="0"/> <!-- 最小值 --> 17 </xs:restriction> 18 </xs:simpleType> 19 20 <!--全局声明复杂类型的声明stu_type --> 21 <xs:complexType name="stu_type"> 22 <xs:sequence> 23 <xs:element ref="姓名"></xs:element> <!-- 声明一个姓名 元素标签 --> 24 <xs:element ref="性别"></xs:element> 25 <xs:element ref="年龄"></xs:element> 26 </xs:sequence> 27 <xs:attribute name="学号" type="xs:string" use="required"/> <!--声明学生的属性 属性值类型为 string , 必须要有。 --> 28 29 </xs:complexType> 30 31 <!--全局声明复杂类型的声明stu_list --> 32 <xs:complexType name="stu_list"> 33 <xs:sequence> 34 <xs:element name="学生" type="stu_type" maxOccurs="unbounded"/> <!-- minOccurs为最少出现个数,maxOccurs为最大出现个数,unbounded为不限制次数 --> 35 </xs:sequence> 36 </xs:complexType> 37 38 <!---元素的声明 --> 39 <xs:element name="姓名" type="xs:token"></xs:element> 40 <xs:element name="性别" type="gender_type"></xs:element> 41 <xs:element name="年龄" type="age_type"></xs:element> 42 <xs:element name="学生" type="stu_type"></xs:element> 43 <xs:element name="学生名册" type="stu_list"></xs:element> 44 </xs:schema>
上面是定义的schema,<<student.xsd>>
, 主要是用来声明复杂类型和简单类型,schame 和DTD 的定义有大部分相同,但是对于它的理解,还是没有太深。其中主要是ref 不能明确其意思
下面是一个xml文档
<?xml version="1.0" encoding="UTF-8"?> <学生名册 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="student.xsd"> <学生 学号="A1"> <姓名>张三</姓名> <性别>男</性别> <年龄>20</年龄> </学生> <学生 学号="A2"> <姓名>李四</姓名> <性别>女</性别> <年龄>19</年龄> </学生> <学生 学号="A3"> <姓名>王二</姓名> <性别>男</性别> <年龄>21</年龄> </学生> </学生名册>
标签:style blog http io color 使用 sp for on
原文地址:http://www.cnblogs.com/JohnChen-happy/p/4116415.html