案例:1
xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3school.com.cn" xmlns="http://www.w3school.com.cn"
elementFormDefault="qualified">
<xs:simpleType name="carType">
<xs:restriction base="xs:string">
<xs:enumeration value="宝马" />
<xs:enumeration value="奥迪" />
<xs:enumeration value="捷豹" />
xs:restriction>
xs:simpleType>
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z][A-Z][0-9]">xs:pattern>
xs:restriction>
xs:simpleType>
xs:element>
<xs:element name="from">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-z]+)">xs:pattern>
xs:restriction>
xs:simpleType>
xs:element>
<xs:element name="heading">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-z][A-Z])+" />
xs:restriction>
xs:simpleType>
xs:element>
<xs:element name="body" type="xs:string" />
<xs:element name="xdate" type="xs:date" fixed="2010-12-10" />
<xs:element name="age" default="12">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0" />
<xs:maxInclusive value="120" />
xs:restriction>
xs:simpleType>
xs:element>
<xs:element name="user">
<xs:complexType>
<xs:sequence>
<xs:element name="sex">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="男|女">xs:pattern>
xs:restriction>
xs:simpleType>
xs:element>
xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
xs:complexType>
xs:element>
<xs:element name="car1" type="carType" />
<xs:element name="car2">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="宝马" />
<xs:enumeration value="奥迪" />
<xs:enumeration value="捷豹" />
xs:restriction>
xs:simpleType>
xs:element>
<xs:element name="phone">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[1][358][0-9]{9}" />
xs:restriction>
xs:simpleType>
xs:element>
xs:sequence>
xs:complexType>
xs:element>
xs:schema>
xml version="1.0" encoding="UTF-8"?>
<note xmlns="http://www.w3school.com.cn"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3school.com.cn note.xsd">
<to>cA4to>
<from>wangfrom>
<heading>aZbVrUheading>
<body>body>
<xdate>2010-12-10xdate>
<age>120age>
<user name="">
<sex>男sex>
user>
<car1>捷豹car1>
<car2>宝马car2>
<phone>13521768697phone>
note>