元属组和属性组的引用

元素组的引用:将若干个元素声明归为一组,当需要进行引用时,直接引用组名。

元素组引用的格式:<xs:group ref="元素组名称"/>

元素组的定义格式:
<xs:group name="元素组名称">
 <!--指示符(xs:all、xs:sequence和xs:choice)-->
 <!--定义多个元素-->
</xs:group>
例:
XML文档:
<?xml version="1.0"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="025.xsd">
<XML>
<name id="001">XML学习天下</name>
<author>张三</author>
<author>李四</author>
<price>88.50</price>
</XML>
<XML>
<name id="002">XML百例</name>
<author>赵五</author>
<price>68.00</price>
</XML>
</books>

Schema文档:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="XML" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:group ref="book"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:group name="book">
<xs:sequence>
<xs:element name="name">
<xs:complexType mixed="true">
<xs:attribute name="id" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="author" type="xs:string" maxOccurs="3"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:group>
</xs:schema>

属性组引用的格式:<xs:attributeGroup ref="属性组名称"/>

属性组的定义格式:
<xs:attributeGroup name="属性组名称">
  <!--定义多个属性-->
</xs:group>
例:
XML文档:
<?xml version="1.0"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="026.xsd">
<name id="001" author="张三" price="88.50">XML学习天下</name>
<name id="002" author="李四" price="68.00">XML百例</name>
<name id="003" author="赵五" price="38.00">XML手册</name>
</books>

Schema文档:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="name" maxOccurs="unbounded">
<xs:complexType mixed="true">
<xs:attributeGroup ref="book_info"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:attributeGroup name="book_info">
<xs:attribute name="id" type="xs:integer" use="required"/>
<xs:attribute name="author" type="xs:string"/>
<xs:attribute name="price" type="xs:decimal"/>
</xs:attributeGroup>
</xs:schema>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值