XML Schemas - Laurentian

Download Report

Transcript XML Schemas - Laurentian

Web Data Management
XML Schema
1
In this lecture
• XML Schemas
• Elements v. Types
• Regular expressions
• Expressive power
Resources
W3C Draft: www.w3.org/TR/2001/REC-xmlschema-1-20010502
2
XML Schemas
•
•
•
•
http://www.w3.org/TR/xmlschema-1/10/2000
generalizes DTDs
uses XML syntax
two documents: structure and datatypes
– http://www.w3.org/TR/xmlschema-1
– http://www.w3.org/TR/xmlschema-2
• XML-Schema is very complex
– often criticized
– some alternative proposals
3
BookCatalogue.dtd
<!ELEMENT BookCatalogue (Book)*>
<!ELEMENT Book (Title, Author, Date, ISBN, Publisher)>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>
<!ELEMENT Date (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT Publisher (#PCDATA)>
4
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns="http://www.publishing.org"
elementFormDefault="qualified">
<xsd:element name="BookCatalogue">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
BookCatalogue.xsd
(explanations on
succeeding pages)
5
xsd = Xml-Schema Definition
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns="http://www.publishing.org"
elementFormDefault="qualified">
<xsd:element name="BookCatalogue">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
All XML Schemas have
"schema" as the root
element.
<!ELEMENT BookCatalogue (Book)*>
<!ELEMENT Book (Title, Author, Date,
ISBN, Publisher)>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>
<!ELEMENT Date (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT Publisher (#PCDATA)>
6
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns="http://www.publishing.org"
elementFormDefault="qualified">
<xsd:element name="BookCatalogue">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
The elements that
are used to create
an XML Schema
come from the
XMLSchema
namespace
7
XMLSchema Namespace
http://www.w3.org/2000/10/XMLSchema
complexType
element
sequence
schema
string
boolean
integer
8
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns="http://www.publishing.org"
elementFormDefault="qualified">
<xsd:element name="BookCatalogue">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
Says that the
elements declared
in this schema
(BookCatalogue,
Book, Title,
Author, Date,
ISBN, Publisher)
are to go in this
namespace
9
Publishing Namespace (targetNamespace)
http://www.publishing.org (targetNamespace)
BookCatalogue
Author
Book
Title
Publisher ISBN
Date
10
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns="http://www.publishing.org"
elementFormDefault="qualified">
<xsd:element name="BookCatalogue">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
The default namespace is
http://www.publishing.org
which is the
targetNamespace!
This is referencing a
Book element declaration.
The Book in what
namespace? Since there
is no namespace qualifier
it is referencing the Book
element in the default
namespace, which is the
targetNamespace!
11
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns="http://www.publishing.org"
elementFormDefault="qualified">
<xsd:element name="BookCatalogue">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Date" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:schema>
This is a directive to
instance documents which
use this schema: Any
elements used by the
instance document which
were declared by this
schema must be namespace
qualified by the namespace
specified by
targetNamespace.
12
Referencing a schema in an XML
instance document
<?xml version="1.0"?>
<BookCatalogue xmlns ="http://www.publishing.org"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="http://www.publishing.org
BookCatalogue.xsd">
<Book>
<Title>My Life and Times</Title>
<Author>Paul McCartney</Author>
<Date>July, 1998</Date>
<ISBN>94303-12021-43892</ISBN>
<Publisher>McMillin Publishing</Publisher>
</Book>
...
</BookCatalogue>
1. First, using a default namespace declaration, tell the schema-validator that all of the elements
used in this instance document come from the publishing namespace.
2. Second, with schemaLocation tell the schema-validator that the http://www.publishing.org
namespace is defined in BookCatalogue.xsd.
3. Third, tell the schema-validator that schemaLocation attribute we are using is the one in the
13
schema instance namespace.
Referencing a schema in an XML
instance document
schemaLocation="A
BookCatalogue.xsd"
BookCatalogue.xml
- uses elements from
namespace A
targetNamespace="A"
BookCatalogue.xsd
- defines elements in
namespace A
14
Note multiple levels of checking
BookCatalogue.xml
BookCatalogue.xsd
Validate that the xml document
conforms to the rules described
in BookCatalogue.xsd
XMLSchema.xsd
(schema-for-schemas)
Validate that BookCatalogue.xsd is a valid
schema document, i.e., it conforms
to the rules described in the
schema-for-schemas
15
Default Value for minOccurs and
maxOccurs
• The default value for minOccurs is "1"
• The default value for maxOccurs is "1"
<element ref="Title" minOccurs="1" maxOccurs="1"/>
Equivalent!
<element ref="Title"/>
16
Qualify XMLSchema,
Default targetNamespace
• In the last example, we explicitly qualified all elements from the XML
Schema namespace. The targetNamespace was the default namespace.
http://www.w3.org/2000/10/XMLSchema
http://www.publishing.org
complexType
BookCatalogue
element
Author
annotation
documentation
Book
Title
Publisher ISBN
sequence
schema
Date
17
Default XMLSchema,
Qualify targetNamespace
• Alternatively (equivalently), we can design our schema so that
XMLSchema is the default namespace.
http://www.w3.org/2000/10/XMLSchema
http://www.publishing.org
complexType
BookCatalogue
element
Author
annotation
documentation
Book
Title
Publisher ISBN
sequence
schema
Date
18
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns:pub="http://www.publishing.org"
elementFormDefault="qualified">
<element name="BookCatalogue">
<complexType>
<sequence>
<element ref="pub:Book" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
<element name="Book">
<complexType>
<sequence>
<element ref="pub:Title"/>
<element ref="pub:Author"/>
<element ref="pub:Date"/>
<element ref="pub:ISBN"/>
<element ref="pub:Publisher"/>
</sequence>
</complexType>
</element>
<element name="Title" type="string"/>
<element name="Author" type="string"/>
<element name="Date" type="string"/>
<element name="ISBN" type="string"/>
<element name="Publisher" type="string"/>
</schema>
Here we are
referencing a
Book element.
Where is that
Book element
defined? In
what namespace?
The pub: prefix
indicates what
namespace this
element is in. pub:
has been set to
be the same as the
targetNamespace.
19
"pub" References the
targetNamespace
http://www.w3.org/2000/10/XMLSchema
http://www.publishing.org (targetNamespace)
complexType
BookCatalogue
element
Author
annotation
documentation
Book
Title
Publisher ISBN
sequence
Date
schema
pub
20
Alternate Schema
• In the previous examples we declared an
element and then we ref’ed that element
declaration. Instead, we can inline the
element declarations.
• On the following slide is an alternate
(equivalent) way of representing the schema
shown previously, using inlined element
declarations.
21
Elements Declared Inline
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns="http://www.publishing.org"
elementFormDefault="qualified">
<xsd:element name="BookCatalogue">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
22
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns="http://www.publishing.org"
elementFormDefault="qualified">
<xsd:element name="BookCatalogue">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Anonymous types (no name)
23
Named Types
• The following slide shows an alternate
(equivalent) schema which uses a named
type.
24
Named Types
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns="http://www.publishing.org"
elementFormDefault="qualified">
<xsd:element name="BookCatalogue">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" type="CardCatalogueEntry" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="CardCatalogueEntry">
<xsd:sequence>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
<xsd:element name="Date" type="xsd:string"/>
<xsd:element name="ISBN" type="xsd:string"/>
<xsd:element name="Publisher" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Named type
25
Please note that
<xsd:element name="A" type="foo"/>
<xsd:complexType name="foo">
<xsd:sequence>
<xsd:element name="B" …/>
<xsd:element name="C" …/>
</xsd:sequence>
</xsd:complexType>
Element A references the
complexType foo.
is equivalent to
<xsd:element name="A">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="B" …/>
<xsd:element name="C" …/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Element A has the
complexType definition
inlined in the element
declaration.
26
type Attribute or complexType
Child Element, but not Both!
• An element declaration can have a type
attribute, or a complexType child element,
but it cannot have both a type attribute and a
complexType child element.
<xsd:element name="A" type="foo">
<xsd:complexType>
…
</xsd:complexType>
</xsd:element>
27
Summary of Declaring Elements
(two ways to do it)
1
<xsd:element name="name" type="type" minOccurs="int" maxOccurs="int"/>
A simple type
(e.g., xsd:string)
or the name of
a complexType
2
A nonnegative
integer
A nonnegative
integer or "unbounded"
Note: minOccurs and maxOccurs can only be used
in nested (local) element declarations.
<xsd:element name="name" minOccurs="int" maxOccurs="int">
<xsd:complexType>
…
</xsd:complexType>
</xsd:element>
28
XML Schemas
<xsd:element name=“paper” type=“papertype”/>
<xsd:complexType name=“papertype”>
<xsd:sequence>
<xsd:element name=“title” type=“xsd:string”/>
<xsd:element name=“author” minOccurs=“0”/>
<xsd:element name=“year”/>
<xsd: choice> < xsd:element name=“journal”/>
<xsd:element name=“conference”/>
</xsd:choice>
</xsd:sequence>
</xsd:element>
DTD: <!ELEMENT paper (title,author*,year, (journal|conference))>
29
Elements v.s. Types in
XML Schema
<xsd:element name=“person”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“name”
type=“xsd:string”/>
<xsd:element name=“address”
type=“xsd:string”/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
DTD:
<xsd:element name=“person”
type=“ttt”/>
<xsd:complexType name=“ttt”>
<xsd:sequence>
<xsd:element name=“name”
type=“xsd:string”/>
<xsd:element name=“address”
type=“xsd:string”/>
</xsd:sequence>
</xsd:complexType>
<!ELEMENT person (name,address)>
30
Elements v.s. Types in
XML Schema
• Types:
– Simple types (integers, strings, ...)
– Complex types (regular expressions, like in DTDs)
• Element-type-element alternation:
–
–
–
–
–
Root element has a complex type
That type is a regular expression of elements
Those elements have their complex types...
...
On the leaves we have simple types
31
Local and Global Types in
XML Schema
• Local type:
<xsd:element name=“person”>
[define locally the person’s type]
</xsd:element>
• Global type:
<xsd:element name=“person” type=“ttt”/>
<xsd:complexType name=“ttt”>
[define here the type ttt]
</xsd:complexType>
Global types: can be reused in other elements
32
Local v.s. Global Elements in
XML Schema
• Local element:
<xsd:complexType name=“ttt”>
<xsd:sequence>
<xsd:element name=“address” type=“...”/>...
</xsd:sequence>
</xsd:complexType>
• Global element:
<xsd:element name=“address” type=“...”/>
<xsd:complexType name=“ttt”>
<xsd:sequence>
<xsd:element ref=“address”/> ...
</xsd:sequence>
</xsd:complexType>
Global elements: like in DTDs
33
Regular Expressions in
XML Schema
Recall the element-type-element alternation:
<xsd:complexType name=“....”>
[regular expression on elements]
</xsd:complexType>
Regular expressions:
•
•
•
•
•
<xsd:sequence> A B C </...>
=ABC
<xsd:choice> A B C </...>
=A|B|C
<xsd:group> A B C </...>
= (A B C)
<xsd:... minOccurs=“0” maxOccurs=“unbounded”> ..</...> = (...)*
<xsd:... minOccurs=“0” maxOccurs=“1”> ..</...>
= (...)?
34
Local Names in XML-Schema
name has
different meanings
in person and
in product
<xsd:element name=“person”>
<xsd:complexType>
. . . . .
<xsd:element name=“name”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=“firstname” type=“xsd:string”/>
<xsd:element name=“lastname” type=“xsd:string”/>
</xsd:sequence>
</xsd:element>
. . . .
</xsd:complexType>
</xsd:element>
<xsd:element name=“product”>
<xsd:complexType>
. . . . .
<xsd:element name=“name” type=“xsd:string”/>
</xsd:complexType>
</xsd:element>
35
Subtle Use of Local Names
<xsd:element name=“A” type=“oneB”/>
<xsd:complexType name=“onlyAs”>
<xsd:choice>
<xsd:sequence>
<xsd:element name=“A” type=“onlyAs”/>
<xsd:element name=“A” type=“onlyAs”/>
</xsd:sequence>
<xsd:element name=“A” type=“xsd:string”/>
</xsd:choice>
</xsd:complexType>
<xsd:complexType name=“oneB”>
<xsd:choice>
<xsd:element name=“B” type=“xsd:string”/>
<xsd:sequence>
<xsd:element name=“A” type=“onlyAs”/>
<xsd:element name=“A” type=“oneB”/>
</xsd:sequence>
<xsd:sequence>
<xsd:element name=“A” type=“oneB”/>
<xsd:element name=“A” type=“onlyAs”/>
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
Arbitrary deep binary tree with A elements, and a single B element
36
Attributes in XML Schema
<xsd:element name=“paper” type=“papertype”/>
<xsd:complexType name=“papertype”>
<xsd:sequence>
<xsd:element name=“title” type=“xsd:string”/>
......
</xsd:sequence>
<xsd:attribute name=“language" type="xsd:NMTOKEN" fixed=“English"/>
</xsd:complexType>
•
•
Attributes are associated to the type, not to the element
Only to complex types; more trouble if we want to add
attributes to simple types.
37
“Mixed” Content, “Any” Type
<xsd:complexType mixed="true">
. . . .
• Better than in DTDs: can still enforce the type, but now
may have text between any elements
<xsd:element name="anything" type="xsd:anyType"/>
....
• Means anything is permitted there
38
“All” Group
<xsd:complexType name="PurchaseOrderType">
<xsd:all> <xsd:element name="shipTo" type="USAddress"/>
<xsd:element name="billTo" type="USAddress"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="items" type="Items"/>
</xsd:all>
<xsd:attribute name="orderDate" type="xsd:date"/>
</xsd:complexType>
• A restricted form of & in SGML
• Restrictions:
– Only at top level
– Has only elements
– Each element occurs at most once
• E.g. “comment” occurs 0 or 1 times
39
Derived Types by Extensions
<complexType name="Address">
<sequence> <element name="street" type="string"/>
<element name="city" type="string"/>
</sequence>
</complexType>
<complexType name="USAddress">
<complexContent>
<extension base="ipo:Address">
<sequence>
<element name="state" type="ipo:USState"/>
<element name="zip" type="positiveInteger"/>
</sequence>
</extension>
</complexContent>
</complexType>
Corresponds to inheritance
40
Derived Types by Restrictions
<complexContent>
<restriction base="ipo:Items“>
… [rewrite the entire content, with restrictions]...
</restriction>
</complexContent>
• (*): may restrict cardinalities, e.g. (0,infty)
to (1,1); may restrict choices; other
restrictions…
Corresponds to set inclusion
41
Simple Types
•
•
•
•
•
•
•
•
•
•
•
String
Token
Byte
unsignedByte
Integer
positiveInteger
Int (larger than integer)
unsignedInt
Long
Short
...
•
•
•
•
•
•
•
Time
dateTime
Duration
Date
ID
IDREF
IDREFS
42
Facets of Simple Types
•Facets = additional properties restricting a simple type
•15 facets defined by XML Schema
Examples
• length
• minLength
• maxLength
• pattern
• enumeration
• whiteSpace
•
•
•
•
•
•
maxInclusive
maxExclusive
minInclusive
minExclusive
totalDigits
fractionDigits
43
Facets of Simple Types
• Can further restrict a simple type by
changing some facets
• Restriction = subset
44
Not so Simple Types
• List types:
<xsd:simpleType name="listOfMyIntType">
<xsd:list itemType="myInteger"/>
</xsd:simpleType>
<listOfMyInt>20003 15037 95977 95945</listOfMyInt>
• Union types
• Restriction types
45
Summary of XML Schema
• Formal Expressive Power:
– Can express precisely the regular tree languages
(over unranked trees)
• Lots of other stuff
– Some form of inheritance
– A “null” value
– Large collection of data types
46
Summary of Schemas
• in SS data:
– graph theoretic
– data and schema are decoupled
– used in data processing
• in XML
– from grammar to object-oriented
– schema wired with the data
– emphasis on semantics for exchange
47