加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Webservice_07_schema进阶

发布时间:2020-12-17 00:12:23 所属栏目:安全 来源:网络整理
导读:RussianDoll.xsd 只有一个根元素,通过嵌套的方式完成编写 优点:结构清晰,根元素只有一个 缺点:元素无法重用 ? ?xml version="1.0" encoding="UTF-8"?schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/2"xmlns:

RussianDoll.xsd

只有一个根元素,通过嵌套的方式完成编写
优点:结构清晰,根元素只有一个
缺点:元素无法重用

?

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/2"
	xmlns:tns="http://www.example.org/2" elementFormDefault="qualified">
	<element name="books">
		<complexType>
			<sequence maxOccurs="unbounded">
				<element name="book" id="bookId">
					<complexType>
						<sequence>
							<element name="title" type="string"></element>
							<choice>
								<element name="author" type="string"></element>
								<element name="authors">
									<complexType>
										<sequence maxOccurs="3">
											<element name="author" type="string"></element>
										</sequence>
									</complexType>
								</element>
							</choice>
							<element name="content" type="string"></element>
						</sequence>
						<attribute name="price" type="int" use="required"></attribute>
					</complexType>
				</element>
			</sequence>
		</complexType>
	</element>
</schema>

?

SalamiSlice.xsd

优点:能够进行最大化重用
缺点:根元素不清晰

?

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/3"
	xmlns:tns="http://www.example.org/3" elementFormDefault="qualified">
	<element name="book" type="tns:bookType"></element>
	<element name="title" type="string"></element>
	<element name="author" type="string"></element>
	<element name="price" type="int"></element>

	<complexType name="bookType">
		<sequence>
			<element ref="tns:title" />
			<element ref="tns:author" />
			<element ref="tns:price" />
		</sequence>
	</complexType>
</schema>

?

VenetianBlind.xsd

最好的选择。

?

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

	<element name="coder" type="tns:coderType" ></element>

	<complexType name="coderType">
		<sequence>
			<element name="name" type="string" />
			<element name="email" type="tns:emailType" />
			<element name="sex" type="tns:sexType" />
		</sequence>
		<attribute name="coderId" type="tns:coderIdType"></attribute>
	</complexType>

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

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

	<simpleType name="coderIdType">
		<restriction base="int">
			<minInclusive value="100"></minInclusive>
			<maxInclusive value="200"></maxInclusive>
		</restriction>
	</simpleType>
</schema>


引入schema

?

Coder.xsd

?

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

	<xsd:element name="coder" type="tns:coderType" />

	<xsd:complexType name="coderType">
		<xsd:sequence>
			<xsd:element name="name" type="xsd:string" />
			<xsd:element name="email" type="tns:emailType" />
			<xsd:element name="sex" type="tns:sexType" />
		</xsd:sequence>
		<xsd:attribute name="coderId" type="tns:coderIdType"/>
	</xsd:complexType>

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

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

	<xsd:simpleType name="coderIdType">
		<xsd:restriction base="xsd:int">
			<xsd:minInclusive value="100"/>
			<xsd:maxInclusive value="200"/>
		</xsd:restriction>
	</xsd:simpleType>
</xsd:schema>


?

Item.xsd

?

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

	<xsd:include schemaLocation="Coder.xsd"/>
	
	<xsd:element name="item" type="tns:itemType" />

	<xsd:complexType name="itemType">
		<xsd:sequence>
			<xsd:element name="name" type="xsd:string" />
			<xsd:element name="boss" type="tns:coderType" />
			<xsd:sequence minOccurs="1" maxOccurs="unbounded">
				<xsd:element name="coder" type="tns:coderType" />
			</xsd:sequence>
		</xsd:sequence>
		<xsd:attribute name="itemId" type="tns:itemIdType" />
	</xsd:complexType>

	<xsd:simpleType name="itemIdType">
		<xsd:restriction base="xsd:int">
			<xsd:minInclusive value="100" />
			<xsd:maxInclusive value="200" />
		</xsd:restriction>
	</xsd:simpleType>
</xsd:schema>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读