Introduction & Overview

Download Report

Transcript Introduction & Overview

An Introduction to XML Schema
CSCI 7818
by Ming Rutar
Resources
XML Schema is a W3C Recommendation
http://www.w3.org/XML/Schema
Motivation
Purpose of DTD :



Sharing grammar/data with others
Validation by the parser
Defaulting of values.
Shortcomings of DTD



a very limited capability for specifying datatypes.
incompatible set of datatypes with those found in
databases
inconsistent syntax with XML
XML Schema Requirements
Structural Schemas
Besides analogizing DTD, there are specific goals
beyond DTD:
 Integration with namespace
 Definition of incomplete constraints on content of an
element type
 Integration of structural schemas with primitive data
types
 inheritance
XML Schema Requirements (2)
Primitive Data Typing

Based on experience with SQL, Java
primitives.
Conformance

Define the relation of schemata to XML
document instances, and obligations on
schema-aware processors.
Example (DTD)
BookStore.dtd
<!ELEMENT BookStore (Book)+>
<!ELEMENT Book (Title, Author, Date, ISBN,
Publisher)>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>
<!ELEMENT Date (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT Publisher (#PCDATA)>
Example (Schema)
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Book" minOccurs="1" 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>
Example (vocabulary)
DTD
BookStore
Schema
ELEMENT
#PCDATA
ATTLIST
ID
NMTOKEN
CDATA
ENTITY
BookStore
Book
Title
Author
Date
ISBN
Publisher
complexType
element
sequence
schema
string
boolean
integer
Data Types

A complex types allow elements in their content and
may carry attributes
 A simple types cannot have element content and
cannot carry attributes, such integer.
 A ur-type definition is present in each ·XML
Schema·, serving as the root of the type definition
hierarchy for that schema.
 Primitive datatypes are those that are not defined in
terms of other datatypes
 Derived datatypes are those that are defined in
terms of other datatypes.
Mapping between DTD and Schema
http://ucsu.colorado.edu/~rutar/map_between_dtd_and_schema.ht
m
An Instance Document
<?xml version="1.0"?>
<BookStore xmlns =http://www.books.org
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
-1
-2
xsi:schemaLocation="http://www.books.org
BookStore.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>
...
</BookStore>
-3
Multiple Level Checking
BookStore.XML
BookStore.xsd
Validator
XMLSchema.xsd
Other way to define name space
Make xsd as default namespace
http://ucsu.colorado.edu/~rutar/BookStore_bk.htm
Compare with
http://ucsu.colorado.edu/~rutar/BookStore_xsd.htm
Conclusion
XML Schemas are a tremendous
advancement over DTDs
 XML Schemas are much more complex
than DTDs
