schema三种书写格式

1、俄罗斯套娃式:整个文档只有一个根节点。所有属性及元素进行嵌套。

优点:结构性强,比较容易看。

缺点:类型重用性低。

代码如下:

<?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 minOccurs="1" maxOccurs="unbounded">
					<element name="book">
						<complexType>
							<sequence>
								<element name = "title"/>
								<element name = "content"/>
								<choice>
									<element name = "author"></element>
									<element name = "authors">
										<complexType>
											<sequence maxOccurs="unbounded">
												<element name = "author" type = "string"/>
											</sequence>
										</complexType>
									</element>
								</choice>
							</sequence>
							<attribute name = "id" type = "int" use = "required" />
						</complexType>
					</element>
				</sequence>
			</complexType>
		</element>
</schema>
2、腊肠式:所有元素与类型定义分离。

优点:重用性强。

缺点:不易维护。

代码:

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

	<element name="book" type="tns:bookType"></element>
	<element name="id" type="int"/>
	<element name="title" type="string"/>
	<element name="content" type="string"/>
	
	
	<complexType name="bookType">
		<sequence>
			<element ref="tns:id"/>
			<element ref="tns:title"/>
			<element ref="tns:content"/>
		</sequence>
	</complexType>
</schema>

3、百叶窗式:集成前面两者的优点。

代码如下:

<?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>



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值