xml文件的基本实例:
对应的xsd文件,也就是newsSchema.xsd文件:
<?xml version="1.0" encoding="utf-8" ?>
<notes xmlns="http://www.robchen.cn/news" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.robchen.cn/news newsSchema.xsd">
<note>
<title>HTML</title>
<summary>Learning HTML</summary>
<author>
<name>Susan Smith</name>
<sex>female</sex>
</author>
<tags>HTML CSS</tags>
<hit date="2007-11-17">267</hit>
<url>http://www.robchen.cn/news/HTML.html</url>
</note>
<note postDate="2007-11-17">
<title>Ajax</title>
<summary>Learning Ajax</summary>
<author>
<sex>male</sex>
<name>Robin Chen</name>
<age>22</age>
</author>
<tags>Ajax JavaScript XML JSON</tags>
<hit date="2007-11-17">854</hit>
<url>http://www.robchen.cn/news/JSON.html</url>
</note>
<note>
<title>XML Schema</title>
<summary>Something About the XML Schema</summary>
<comment>Nice</comment>
<author>
<name>Robin Chen</name>
<age>22</age>
</author>
<url>http://www.robchen.cn/news/XMLSchema.htm</url>
</note>
</notes>
对应的xsd文件,也就是newsSchema.xsd文件:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1" targetNamespace="http://www.robchen.cn/news" elementFormDefault="qualified" xmlns="http://www.robchen.cn/news" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="notes" type="Notes">
</xs:element>
<xs:element name="comment" type="xs:string">
</xs:element>
<xs:complexType name="Notes">
<xs:sequence>
<xs:element name="note" type="Note" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Note">
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="summary" type="xs:string" />
<xs:element ref="comment" minOccurs="0" />
<xs:element name="author" type="AuthorType" maxOccurs="unbounded" />
<xs:element name="tags" type="TagsType" minOccurs="0" />
<xs:element name="hit" type="HitType" default="0" minOccurs="0" />
<xs:element name="url" type="UrlType" />
</xs:sequence>
<xs:attribute name="postDate" default="2007-11-17" type="xs:date" />
</xs:complexType>
<xs:complexType name="AuthorType">
<xs:all>
<xs:element name="name" type="xs:string" minOccurs="1" />
<xs:element name="sex" type="SexType" minOccurs="0" />
<xs:element name="age" type="AgeType" minOccurs="0" />
</xs:all>
</xs:complexType>
<xs:simpleType name="SexType">
<xs:restriction base="xs:string">
<xs:enumeration value="male" />
<xs:enumeration value="female" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="AgeType">
<xs:restriction base="xs:integer">
<xs:maxInclusive value="80" />
<xs:minInclusive value="20" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TagType">
<xs:list itemType="xs:token">
</xs:list>
</xs:simpleType>
<xs:simpleType name="TagsType">
<xs:restriction base="TagType">
<xs:minLength value="0" />
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="HitType">
<xs:simpleContent>
<xs:extension base="xs:nonNegativeInteger">
<xs:attribute name="date" type="xs:date" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="UrlType">
<xs:restriction base="xs:string">
<xs:pattern value="http://www.robchen.cn/news/.*\.(html|htm)"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:schema>