XML - DTD & Schema
XML - DTD & Schema
XML - DTD & Schema
References
• W3Schools Website
– http://www.w3schools.com/dtd/default.asp
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
elements to be of the type "#PCDATA
External DOCTYPE declaration
• If the DTD is external to your XML source file, it should be
wrapped in a DOCTYPE definition with the following syntax:
<date type="date">2004-03-11</date>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A Simple DTD
• This is a simple DTD file called "note.dtd" that defines the
elements of the XML document above ("note.xml"):
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM
"http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A Reference to an XML Schema
• This XML document has a reference to an XML Schema:
<?xml version="1.0"?>
<note
xmlns=http://www.w3schools.com
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XSD - The <schema> Element
The <schema> element is the root element of
every XML Schema!
The <schema> Element
• The <schema> element is the root element of every XML
Schema:
<?xml version="1.0"?>
<xs:schema>
...
...
</xs:schema>
The <schema> Element
• The <schema> element may contain some attributes. A
schema declaration often looks something like this:
<?xml version="1.0"?>
<xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema
targetNamespace=http://www.w3schools.com
xmlns=http://www.w3schools.com
elementFormDefault="qualified">
...
...
</xs:schema>
Elements and data types used in the
Elements defined by this
schema (schema, element, complexType,
schema (note, to, from,
sequence, string, boolean, etc.) come from
heading, body) come from the
the "http://www.w3.org/2001/XMLSchema"
"http://www.w3schools.com"
namespace.
namespace.
Elements and data types that come from
the "http://www.w3.org/2001/XMLSchema"
namespace should be prefixed with xs:
<?xml version="1.0"?>
<xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema
targetNamespace=http://www.w3schools.com
xmlns=http://www.w3schools.com
elementFormDefault="qualified">
...
...
</xs:schema>
<?xml version="1.0"?>
<note xmlns=http://www.w3schools.com
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Specifies the default namespace declaration.
This declaration tells the schema-validator XML Schema Instance
that all the elements used in this XML namespace available
document are declared in the (Now schemaLocation
"http://www.w3schools.com" namespace. attribute can be used.
It has two values)
<?xml version="1.0"?>
<note xmlns=http://www.w3schools.com
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<lastname>Refsnes</lastname>
<age>34</age>
<dateborn>1968-03-27</dateborn>
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Restrictions on a Set of Values
• To limit the content of an XML element to a set of acceptable
values, we would use the enumeration constraint.
• This example defines an element called "car":
<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
• The "car" element is a simple type with a restriction. The
acceptable values are: Audi, Golf, BMW.
Restrictions on a Set of Values
• The example above could also have been written like this:
<xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z][A-Z][A-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="choice">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[xyz]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="prodid">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-z])*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-z][A-Z])+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="gender">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="male|female"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]{8}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="address">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="address">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="replace"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="address">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
• This "password" element is a simple type with a restriction.
The value must be minimum five characters and maximum
eight characters.
Restrictions for Datatypes
Constraint Description
fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero
length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero
maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value)
maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value)
maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than
zero
minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value)
minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than
zero
pattern Defines the exact sequence of characters that are acceptable
totalDigits Specifies the exact number of digits allowed. Must be greater than zero
whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled
XSD String Data Types
String data types are used for values that
contains character strings.
String Data Type
• The string data type can contain characters, line feeds,
carriage returns, and tab characters.
• The following is an example of a string declaration in a
schema:
<xs:element name="customer" type="xs:string"/>
The XML processor will not modify the value if you use
the string data type.
NormalizedString Data Type
• The normalizedString data type is derived from the String data type.
• The normalizedString data type also contains characters, but the XML
processor will remove line feeds, carriage returns, and tab characters.
• The following is an example of a normalizedString declaration in a schema:
<customer>John Smith</customer>
• Or it might look like this:
<customer>John Smith</customer>
• Or it might look like this:
In the example above the XML processor will remove the tabs
String Data Types
• All of the data types below derive from the String data type (except for
string itself)!
Name Description
ENTITIES
ENTITY
ID A string that represents the ID attribute in XML (only used with
IDREF schema
A string attributes)
that represents the IDREF attribute in XML (only used
IDREFS with schema attributes)
language A string that contains a valid language id
Name A string that contains a valid XML name
NCName
NMTOKEN A string that represents the NMTOKEN attribute in XML (only
NMTOKENS used with schema attributes)
normalizedStrin A string that does not contain line feeds, carriage returns, or
g tabs
QName
string A string
token A string that does not contain line feeds, carriage returns, tabs,
leading or trailing spaces, or multiple spaces
Restrictions on String Data Types
• Restrictions that can be used with String data types:
– enumeration
– length
– maxLength
– minLength
– pattern (NMTOKENS, IDREFS, and ENTITIES cannot
use this constraint)
– whiteSpace
XSD Date and Time Data Types
Date and time data types are used for values
that contain date and time.
Date Data Type
• The date data type is used to specify a date.
• The date is specified in the following form "YYYY-MM-DD"
where:
– YYYY indicates the year
– MM indicates the month
– DD indicates the day
• All components are required!
• The following is an example of a date declaration in a
schema:
<xs:element name="start" type="xs:date"/>
<start>2002-09-24</start>
Time Zones
• To specify a time zone, you can either enter a date in UTC
time by adding a "Z" behind the date - like this:
<start>2002-09-24Z</start>
<start>2002-09-24-06:00</start>
or
<start>2002-09-24+06:00</start>
DateTime Data Type
• The dateTime data type is used to specify a date and a
time.
• The dateTime is specified in the following form "YYYY-MM-
DDThh:mm:ss" where:
• YYYY indicates the year
– MM indicates the month
– DD indicates the day
– T indicates the start of the required time section
– hh indicates the hour
– mm indicates the minute
– ss indicates the second
• Note: All components are required!
DateTime Data Type
• The following is an example of a dateTime declaration in a
schema:
<startdate>2002-05-30T09:00:00</startdate>
<startdate>2002-05-30T09:30:10.5</startdate>
Duration Data Type
• The duration data type is used to specify a time interval.
• The time interval is specified in the following form
"PnYnMnDTnHnMnS" where:
– P indicates the period (required)
– nY indicates the number of years
– nM indicates the number of months
– nD indicates the number of days
– T indicates the start of a time section (required if you are
going to specify hours, minutes, or seconds)
– nH indicates the number of hours
– nM indicates the number of minutes
– nS indicates the number of seconds
Duration Data Type
• The following is an example of a duration declaration in a
schema:
<period>P5Y</period>
<period>P5Y2M10D</period>
Duration Data Type
• A period of five years, two months, 10 days, and 15
hours
<period>P5Y2M10DT15H</period>
• A period of 15 hours
<period>PT15H</period>
Negative Duration
• To specify a negative duration, enter a minus sign before
the P:
• A period of minus 10 days
<period>-P10D</period>
Date and Time Data Types
Name Description
<prize>+999.5450</prize> <prize>-999.5450</prize>
or
<prize0</prize> <prize14</prize>
<prize>+999</prize> <prize>-999</prize>
or
<prize0</prize>
• A period of 15 hours
<prize disabled="true">999</prize>
anyURI
base64Binary
boolean
double
float
hexBinary
NOTATION
QName
Restrictions on Miscellaneous Data
Types
• Restrictions that can be used with other data types:
– enumeration
(a Boolean data type cannot use this constraint)
– length
(a Boolean data type cannot use this constraint)
– maxLength
(a Boolean data type cannot use this constraint)
– minLength
(a Boolean data type cannot use this constraint)
– pattern
– whiteSpace
XSD Complex Elements
A complex element contains other elements
and/or attributes.
What is a Complex Element?
• A complex element is an XML element that contains other
elements and/or attributes.
• There are four kinds of complex elements:
– empty elements
– elements that contain only other elements
– elements that contain only text
– elements that contain both other elements and text
<description>
It happened on <date lang="norwegian">03.03.99</date>..
</description>
How to Define a Complex
Element
• Look at this complex XML element, "employee",
which contains only other elements:
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Only the "employee" element can use the specified complex type.
Notice that the child elements, "firstname" and "lastname", are surrounded by the
<sequence> indicator. This means that the child elements must appear in the same
order as they are declared; "firstname" first and "lastname" second.
How to Define a Complex
Element
2. The "employee" element can have a type attribute that
refers to the name of the complex type to use:
Examples…
<xs:element name="employee" type="personinfo"/>
<xs:element name="student" type="personinfo"/>
<xs:element name="member" type="personinfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="employee" type="fullpersoninfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="fullpersoninfo">
<xs:complexContent>
<xs:extension base="personinfo">
<xs:sequence>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
XSD Complex Type Elements
Only
An "elements only" complex type contains an
element that contains only other elements.
Define Complex Types with Elements
Only
• An XML element, "person", that contains only other
elements:
<person>
<firstname>John</firstname>
<lastname>Smith</lastname>
</person>
Define Complex Types with Elements
Only
• You can define the "person" element in a schema,
like this:
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="basetype">
....
....
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Define Complex Text-Only Elements
OR
<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="basetype">
....
....
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Define Complex Text-Only Elements
• Tip: Use the extension element to expand on the
base simple type for the element, and use the
restriction element to limit the base simple type for
the element.
• Here is an example of an XML element, "shoesize",
that contains text-only:
<shoesize country="france">35</shoesize>
Define Complex Text-Only Elements
• The following example declares a complexType,
"shoesize". The content is defined as an integer data
type and the "shoesize" element also contains an
attribute named "country":
<xs:element name="shoesize">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Define Complex Text-Only Elements
• We could also give the complexType element a name,
and let the "shoesize" element have a type attribute that
refers to the name of the complexType (if you use this
method, several elements can refer to the same
complex type):
<letter>
Dear Mr.<name>John Smith</name>.
Your order <orderid>1032</orderid>
will be shipped on <shipdate>2001-07-13</shipdate>.
</letter>
<xs:element name="letter">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="orderid" type="xs:positiveInteger"/>
<xs:element name="shipdate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
To enable character data to appear between the child-elements of "letter",
the mixed attribute must be set to "true". The <xs:sequence> tag means
that the elements defined (name, orderid and shipdate) must appear in
that order inside a "letter" element.
Define Complex Types with Mixed
Content
• We could also give the complexType element a name,
and let the "letter" element have a type attribute that
refers to the name of the complexType
<xs:element name="letter" type="lettertype"/>
<xs:complexType name="lettertype" mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="orderid" type="xs:positiveInteger"/>
<xs:element name="shipdate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
When using the <all> indicator you can set the <minOccurs>
indicator to 0 or 1 and the <maxOccurs> indicator can only be set
to 1 (the <minOccurs> and <maxOccurs> are described later).
Choice Indicator
• The <choice> indicator specifies that either one
child element or another can occur:
<xs:element name="person">
<xs:complexType>
<xs:choice>
<xs:element name="employee" type="employee"/>
<xs:element name="member" type="member"/>
</xs:choice>
</xs:complexType>
</xs:element>
Sequence Indicator
• The <sequence> indicator specifies that the child
elements must appear in a specific order:
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
maxOccurs Indicator
• The <maxOccurs> indicator specifies the maximum
number of times an element can occur:
<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string“
maxOccurs="10" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
The example above indicates that the "child_name" element can
occur a minimum of zero times and a maximum of ten times in a
"person" element.
Note
• When using the <all> indicator you can set the
<minOccurs> indicator to 0 or 1 and the
<maxOccurs> indicator can only be set to 1
• For all "Order" and "Group" indicators (any, all,
choice, sequence, group name, and group
reference) the default value for maxOccurs and
minOccurs is 1!!!!!
A working example:
• To allow an element to appear an unlimited number
of times, use the maxOccurs="unbounded"
statement:
<xs:group name="persongroup">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="birthday" type="xs:date"/>
</xs:sequence>
</xs:group>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:group ref="persongroup"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
Attribute Groups
• Attribute groups are defined with the attributeGroup
declaration, like this:
<xs:attributeGroup name="groupname">
...
</xs:attributeGroup>
Attribute Groups
• The following example defines an attribute group named
"personattrgroup":
<xs:attributeGroup name="personattrgroup">
<xs:attribute name="firstname" type="xs:string"/>
<xs:attribute name="lastname" type="xs:string"/>
<xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>
<xs:element name="person">
<xs:complexType>
<xs:attributeGroup ref="personattrgroup"/>
</xs:complexType>
</xs:element>
XSD The <any> Element
The <any> element enables us to extend the
XML document with elements not specified
by the schema!
The <any> Element
• The <any> element enables us to extend the XML
document with elements not specified by the
schema.
• The following example is a fragment from an XML
schema called "family.xsd".
family.xsd
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:any minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
The <any> Element
• Now we want to extend the "person" element with a
"children" element. In this case we can do so, even
if the author of the schema above never declared
any "children" element!
• Look at this schema file, called "children.xsd":
children.xsd
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema
targetNamespace=http://www.w3schools.com
xmlns=http://www.w3schools.com
elementFormDefault="qualified">
<xs:element name="children">
<xs:complexType>
<xs:sequence>
<xs:element name="childname" type="xs:string“
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The <any> Element
• The XML file below (called "Myfamily.xml"), uses
components from two different schemas;
"family.xsd" and "children.xsd":
• The XML file above is valid because the schema
"family.xsd" allows us to extend the "person"
element with an optional element after the
"lastname" element!
• The <any> and <anyAttribute> elements are used
to make EXTENSIBLE documents! They allow
documents to contain additional elements that are
not declared in the main XML schema!
Myfamily.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<persons xmlns=http://www.microsoft.com
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:SchemaLocation="http://www.microsoft.com family.xsd
http://www.w3schools.com children.xsd">
<person>
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>
<children>
<childname>Cecilie</childname>
</children>
</person>
<person>
<firstname>Stale</firstname>
<lastname>Refsnes</lastname>
</person>
</persons>
XSD The <anyAttribute> Element
The <anyAttribute> element enables us to
extend the XML document with attributes not
specified by the schema!
The <anyAttribute> Element
• The following example is a fragment from an XML
schema called "family.xsd".
• It shows a declaration for the "person" element. By using
the <anyAttribute> element we can add any number of
attributes to the "person" element:
family.xsd
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>
The <anyAttribute> Element
or like this:
<kunde>
<navn>John Smith</navn>
</kunde>
Blocking Element Substitution
• To prevent other elements from substituting with a
specified element, use the block attribute:
<xs:element name="name" type="xs:string" block="substitution"/>
<kunde>
<navn>John Smith</navn>
</kunde>
Using substitutionGroup
• The type of the substitutable elements must be the
same as, or derived from, the type of the head
element. If the type of the substitutable element is
the same as the type of the head element you will
not have to specify the type of the substitutable
element.
• Note that all elements in the substitutionGroup (the
head element and the substitutable elements) must
be declared as global elements, otherwise it will not
work!
What are Global Elements?
• Global elements are elements that are immediate
children of the "schema" element! Local elements
are elements nested within other elements!
An XSD Example
This chapter will demonstrate how to write an
XML Schema. You will also learn that a
schema can be written in different ways.
An XML Document
• Let's have a look at this XML document called
"shiporder.xml":
...
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:noNamespaceSchemaLocation="shiporder.xsd">
...
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Remember???
<xs:restriction base="xs:string">
Using Named Types
• The restriction element is more often used to apply
restrictions on elements. Look at the following lines from
the schema above:
<xs:simpleType name="orderidtype">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{6}"/>
</xs:restriction>
</xs:simpleType>