Definitive XML Schema
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0132886723
2nd edition, , Prentice Hall PTR.
Chapter 1: Schemas: an introduction
Full example
This example consists of a very simple instance and schema.
<product effDate="2001-04-02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="chapter01.xsd"> <number>557</number> <size>10</size> </product>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="product" type="ProductType"/> <xs:complexType name="ProductType"> <xs:sequence> <xs:element name="number" type="xs:integer"/> <xs:element name="size" type="SizeType"/> </xs:sequence> <xs:attribute name="effDate" type="xs:date"/> </xs:complexType> <xs:simpleType name="SizeType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> </xs:restriction> </xs:simpleType> </xs:schema>
Book examples
<product effDate="2001-04-12"> <number>557</number> <size>10</size> </product>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="product" type="ProductType"/> <xs:complexType name="ProductType"> <xs:sequence> <xs:element name="number" type="xs:integer"/> <xs:element name="size" type="SizeType"/> </xs:sequence> <xs:attribute name="effDate" type="xs:date"/> </xs:complexType> <xs:simpleType name="SizeType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="2"/> <xs:maxInclusive value="18"/> </xs:restriction> </xs:simpleType> </xs:schema>
<!ELEMENT product (number, size?)> <!ELEMENT number (#PCDATA)> <!ELEMENT size (#PCDATA)> <!ATTLIST product effDate CDATA #IMPLIED>