空元素的定义:没有内容的元素。
含有属性的空元素:
例:
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,一般情况下复杂内容是不允许含有文本的。
含有属性的空元素:
例:
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,一般情况下复杂内容是不允许含有文本的。