webservice 第二讲schema

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/01"
xmlns:tns="http://www.example.org/01"
elementFormDefault="qualified">
<element name="user">
<complexType>
<sequence>
<element name="id" type="int"/>
<element name="username" type="string"/>
<element name="born" type="date"/>
</sequence>
</complexType>
</element>
</schema>


1.http://www.w3.org/2001/XMLSchema
Schema 默认命名空间,不能修改,但是可以增加前缀。如何增加前缀之后所有的element元素都要增加浅醉
2.targetNamespace="http://www.example.org/01"
自己这个文档的命令空间,可以方便其他xml和schema文件的引用
3.xmlns:tns="http://www.example.org/01"
此处的名称和自己的命名空间一直,增加了tns的前缀,此时如果要引用当前文件创建的类型,需要加上tns前缀

<?xml version="1.0" encoding="UTF-8"?>
<user xmlns="http://www.example.org/01"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/01 01.xsd">
<id>1</id>
<username>wxh</username>
<born>1998-12-12</born>
</user>



4.复杂的schema文件和xml文件相关配置
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/04"
xmlns:tns="http://www.example.org/04"
elementFormDefault="qualified">

<element name="person" type="tns:personType"/>

<complexType name="personType">
<sequence>
<element name="name" type="string"/>
<element name="age" type="tns:ageType"/>
<element name="email" type="tns:emailType"/>
</sequence>
<attribute name="sex" type="tns:sexType"/>
</complexType>

<simpleType name="emailType">
<restriction base="string">
<pattern value="(\w+\.*)*\w+@\w+\.[A-Za-z]{2,6}"/>
<minLength value="6"/>
<maxLength value="255"/>
</restriction>
</simpleType>

<simpleType name="ageType">
<restriction base="int">
<minInclusive value="1"/>
<maxExclusive value="150"/>
</restriction>
</simpleType>

<simpleType name="sexType">
<restriction base="string">
<enumeration value="男"/>
<enumeration value="女"/>
</restriction>
</simpleType>
</schema>



<?xml version="1.0" encoding="UTF-8"?>
<person xmlns="http://www.example.org/04"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/04 04.xsd" sex="男">
<name>搜索</name>
<age>149</age>
<email>101035601@136.com</email>
</person>


54.复杂的schema文件
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/classroom"
xmlns:tns="http://www.example.org/classroom"
elementFormDefault="qualified">
<xsd:element name="student" type="tns:studentType"/>

<xsd:complexType name="studentType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="sex" type="tns:sexType"/>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="sexType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="男"/>
<xsd:enumeration value="女"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>


<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/classroom"
xmlns:tns="http://www.example.org/classroom"
elementFormDefault="qualified">
<xsd:include schemaLocation="student.xsd"/>

<xsd:element name="classroom" type="tns:classroomType"/>

<xsd:complexType name="classroomType">
<xsd:sequence>
<xsd:element name="grade" type="tns:gradeType"/>
<xsd:element name="name" type="xsd:string"/>
<!-- <xsd:element name="stus">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="unbounded">
<xsd:element name="student" type="tns:studentType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
-->
<xsd:sequence minOccurs="1" maxOccurs="unbounded">
<xsd:element name="student" type="tns:studentType"/>
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="gradeType">
<xsd:restriction base="xsd:int">
<xsd:minInclusive value="2000"/>
<xsd:maxInclusive value="3000"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值