源:http://www.cnblogs.com/chenqingwei/archive/2010/05/10/1731743.html
评:
具体可参考:
http://blog.csdn.net/evanerv0079/archive/2008/06/05/2515313.aspx
复制代码
复制代码
<?xml version="1.0" encoding="gb2312"?>
<studentlist>
<student id="A101">
<name>李华</name>
<sex>男</sex>
<birthday>1978.9.12</birthday>
<score>92</score>
<skill>Java</skill>
<skill>Oracle</skill>
<skill>C Sharp</skill>
<skill>SQL Server</skill>
</student>
<studentlist>
复制代码
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="原子类型" targetNamespace="http://student.com" elementFormDefault="qualified"
xmlns="http://student.com" xmlns:mstns="http://student.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="nameType"/>
<xs:element ref="age"/>
<xs:element ref="sex"/>
<xs:element ref="phone"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="nameType">
<xs:restriction base="xs:string">
<xs:minLength value="4"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="sex">
<xs:simpleType>
<xs:restriction base="xs:string">
<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="\d{3}-\d{8}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
复制代码
MSDN上面一个例子:
复制代码
<!-- booksSchema.xml -->
<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore xmlns = "schema.xsd">
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<first-name>Sidas</first-name>
<last-name>Plato</last-name>
</author>
<price>9.99</price>
</book>
</bookstore>
复制代码
<!-- schema.xsd -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="schema.xsd"
elementFormDefault="qualified"
targetNamespace="schema.xsd">
<xsd:element name="bookstore" type="bookstoreType"/>
<xsd:complexType name="bookstoreType">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="book" type="bookType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="bookType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="author" type="authorName"/>
<xsd:element name="price" type="xsd:decimal"/>
</xsd:sequence>
<xsd:attribute name="genre" type="xsd:string"/>
<xsd:attribute name="publicationdate" type="xsd:string"/>
<xsd:attribute name="ISBN" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="authorName">
<xsd:sequence>
<xsd:element name="first-name" type="xsd:string"/>
<xsd:element name="last-name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
复制代码
<!-- bookSchemaFail.xml -->
<?xml version='1.0'?>
<bookstore xmlns="schema.xsd">
<book>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
</book>
<book genre="novel">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
评:
具体可参考:
http://blog.csdn.net/evanerv0079/archive/2008/06/05/2515313.aspx
复制代码
复制代码
<?xml version="1.0" encoding="gb2312"?>
<studentlist>
<student id="A101">
<name>李华</name>
<sex>男</sex>
<birthday>1978.9.12</birthday>
<score>92</score>
<skill>Java</skill>
<skill>Oracle</skill>
<skill>C Sharp</skill>
<skill>SQL Server</skill>
</student>
<studentlist>
复制代码
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="原子类型" targetNamespace="http://student.com" elementFormDefault="qualified"
xmlns="http://student.com" xmlns:mstns="http://student.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="nameType"/>
<xs:element ref="age"/>
<xs:element ref="sex"/>
<xs:element ref="phone"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="nameType">
<xs:restriction base="xs:string">
<xs:minLength value="4"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="sex">
<xs:simpleType>
<xs:restriction base="xs:string">
<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="\d{3}-\d{8}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
复制代码
MSDN上面一个例子:
复制代码
<!-- booksSchema.xml -->
<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore xmlns = "schema.xsd">
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<first-name>Sidas</first-name>
<last-name>Plato</last-name>
</author>
<price>9.99</price>
</book>
</bookstore>
复制代码
<!-- schema.xsd -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="schema.xsd"
elementFormDefault="qualified"
targetNamespace="schema.xsd">
<xsd:element name="bookstore" type="bookstoreType"/>
<xsd:complexType name="bookstoreType">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="book" type="bookType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="bookType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="author" type="authorName"/>
<xsd:element name="price" type="xsd:decimal"/>
</xsd:sequence>
<xsd:attribute name="genre" type="xsd:string"/>
<xsd:attribute name="publicationdate" type="xsd:string"/>
<xsd:attribute name="ISBN" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="authorName">
<xsd:sequence>
<xsd:element name="first-name" type="xsd:string"/>
<xsd:element name="last-name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
复制代码
<!-- bookSchemaFail.xml -->
<?xml version='1.0'?>
<bookstore xmlns="schema.xsd">
<book>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
</book>
<book genre="novel">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>