1. XML Schema Definition
1. XML Schema Definition
XML Schema(XML Schema Definition,XSD)用于描述 XML 文档的结构
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="BOOKS">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="BOOK" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="BOOK">
<xs:complexType>
<xs:sequence>
<xs:element name="TITLE" type="xs:string"/>
<xs:element name="AUTHOR" type="xs:string"/>
<xs:element name="PAGE" type="xs:int"/>
<xs:choice>
<xs:element name="PRICE" type="xs:decimal"/>
<xs:element name="DISCOUNT" type="xs:decimal"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<BOOKS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BOOKS.xsd">
<BOOK>
<TITLE>XML</TITLE>
<AUTHOR>JIM</AUTHOR>
<PAGE>30</PAGE>
<PRICE>20</PRICE>
</BOOK>
<BOOK>
<TITLE>XML</TITLE>
<AUTHOR>JIM</AUTHOR>
<PAGE>30</PAGE>
<DISCOUNT>10</DISCOUNT>
</BOOK>
<BOOK>
<TITLE>XML</TITLE>
<AUTHOR>JIM</AUTHOR>
<PAGE>30</PAGE>
<PRICE>20</PRICE>
</BOOK>
</BOOKS>