Definitive XML Schema
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0130655678
1st 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-02"> <number>557</number> <size>10</size> </product>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="product" type="ProductType"/> <xsd:complexType name="ProductType"> <xsd:sequence> <xsd:element name="number" type="xsd:integer"/> <xsd:element name="size" type="SizeType"/> </xsd:sequence> <xsd:attribute name="effDate" type="xsd:date"/> </xsd:complexType> <xsd:simpleType name="SizeType"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="18"/> </xsd:restriction> </xsd:simpleType> </xsd:schema>
<!ELEMENT product (number, size?)> <!ELEMENT number (#PCDATA)> <!ELEMENT size (#PCDATA)> <!ATTLIST product effDate CDATA #IMPLIED>