SCHEMA典型范例

来源:互联网 发布:sql语句查询信息语句 编辑:程序博客网 时间:2024/05/15 19:13

XML的需求:

<学校>
<级部>
<名称></名称>
<班级>
<名称></名称>
<课程></课程>
<人数></人数>
</班级>
</级部>
</学校>

其中<级部>要求一个或多个,<级部>可包含一个或多个<班级>

<名称>要求文本类型
<人数>要求数字类型
<课程>要求枚举类型,其中包括“语文”、“数学”、“英语”

 

SCHEMA ( xml.xsd ) :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:element name="学校">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="级部" type="jb" minOccurs="1" maxOccurs="unbounded"/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
 <xs:complexType name="jb">
  <xs:sequence>
   <xs:element name="名称" type="xs:string"/>
   <xs:element name="班级" type="bj" minOccurs="1" maxOccurs="unbounded"/>
  </xs:sequence>
 </xs:complexType>
 <xs:complexType name="bj">
  <xs:all>
   <xs:element name="名称" type="xs:string"/>
   <xs:element name="课程" type="kc"/>
   <xs:element name="人数" type="xs:int"/>
  </xs:all>
 </xs:complexType>
 <xs:simpleType name="kc">
  <xs:restriction base="xs:string">
   <xs:pattern value="语文|数学|英语"/>
<!-- 这个部分也可以用枚举的形式,如下:
   <xs:enumeration value="语文"/>
   <xs:enumeration value="数学"/>
   <xs:enumeration value="英语"/>
-->
  </xs:restriction>
 </xs:simpleType>
</xs:schema>


XML例子:

<?xml version="1.0" encoding="UTF-8"?>
<学校 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xml.xsd">
 <级部>
  <名称>1j</名称>
  <班级>
   <名称>1b</名称>
   <课程>语文</课程>
   <人数>22</人数>
  </班级>
  <班级>
   <名称>2b</名称>
   <课程>数学</课程>
   <人数>22</人数>
  </班级>
  <班级>
   <名称>3b</名称>
   <课程>英语</课程>
   <人数>22</人数>
  </班级>
 </级部>
</学校>

 

原创粉丝点击