特殊的复杂类型

空元素的定义:没有内容的元素。

含有属性的空元素:
例:
XML文档:
<?xml version="1.0"?>
<book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="020.xsd"
id="001" name="XML学习天下"/>

Schema文档:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book">
<xs:complexType>
<xs:attribute name="id" type="xs:integer"/>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>

不含有属性的空元素:
例:
XML文档:
<?xml version="1.0"?>
<book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="021.xsd"/>

Schema文档:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book">
<xs:complexType/>
</xs:element>
</xs:schema>

混合内容类型的定义:
  指一个元素内容中既含有文本,又含有子元素。
例:
XML文档:
<?xml version="1.0"?>
<book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="022.xsd">
关于书的介绍
<name>XML学习天下</name>
<author>张三</author>
<author>李四</author>
<author>赵五</author>
</book>

Schema文档:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book">
<xs:complexType mixed="true">  /mixed="true":允许复杂内容中可以含有文本
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="author" type="xs:string" maxOccurs="3"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
注:mixed的默认值为false,一般情况下复杂内容是不允许含有文本的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值