Title: XML SCHEMA
1XML SCHEMA
2XML Schema
- Status
- Motivation
- Simple type
- Predefined vs. Derived
- Complex type
- Sequence
- Occurrences
- List, Union
- Choice, Group
3XML Schema Status
- W3C candidate recommendation as of Oct. 2000
- http//www.w3.org/XML/Schema.html
- XML schema aware tools
- Several free and commercial versions available
(Check the above site) - Apache Xerces
- DTD to XML Schema conversion tool
- XML Schema 1.0 Recommendation in May 2001
- XML Schema 1.1 Working Group is currently working
to develop a set of requirements for XML Schema
1.1, which is intended to be mostly compatible
with XML Schema 1.0 and to have approximately the
same scope.
4XML Schema Motivations
- Provide more powerful and flexible schema
language than DTD - Represent XML document syntax in XML language
- XML tools can be readily used
- Support non-textual data types
- Important to B2B, e-Commerce
- Handle complex syntax
5Valid VS Schema Valid
- XML schema is not part of XML 1.0
- XML document that is validated with DTD is
valid - XML document that conforms to XML schema is
schema-valid - XML document that conforms to a particular XML
schema is called instance document of that
schema
6Schema Data Types
- Simple type
- Do not have sub-elements
- Do not have element sub-elements
- Do not have attribute sub-elements
- Predefined type or derived from predefined type
- Complex type
- Have either element sub-elements or attribute
sub-elements
7Four Main Schema Elements
- xsdelement declares an element and assigns it a
type. - xsdattribute declares an attribute and assigns
it a type. - xsdcomplexType defines a new complex type.
- xsdsimpleType defines a new simple type.
8Definition and Declaration
- Definition
- Create new types (both simple and complex types)
- Declaration
- Enable elements and attributes with specific
names and types (both simple and complex) to
appear in document instances.
9Example
- lt!-- Definition --gt
- ltxsdsimpleType name"zipUnion"gt
- ltxsdunion memberTypes"USState
listOfMyIntType"/gt - lt/xsdsimpleTypegt
- lt!-- Declaration --gt
- ltelement namezips typezipUniongt
10Predefined Simple Types
- String, CDATA, token, byte, unsignedByte, binary,
- integer, positiveInteger, negativeInteger,
- nonNegativeInteger, nonPositiveInteger, int,
- unsignedInt, long, unsignedLong, short,
- unsignedShort, decimal, float, double, boolean,
- time, timeInstant, timePeriod, timeDuration,
date, - month, year, century, recurringDay,
recurringDate, - recurringDuration, Name, Qname, NCName,
- uriReference, language, ID, IDREF, IDREFS,
- ENTITY, ENTITIES, NOTATION, NMTOKEN,
- NMTOKENS
11Examples of Predefined Simple Type
- ltelement nameTitle typestring/gt
- ltelement nameHeading typestring/gt
- ltelement nameTopic typestring/gt
- ltelement namePrice typedecimal/gt
- ltattribute namefocus typestring/gt
12Derived Simple Type
- Derived from existing simple types (predefined or
derived) - Typically restricting existing simple type
- The legal range of values for a new type is
subset of the ones of existing type - Existing type is called base type
- Use restriction element along with facets to
restrict the range of values
13Example of Derived Simple Type 1(Numeric Range)
- ltxsdsimpleType name"myInteger"gt
- ltxsdrestriction base"xsdinteger"gt
- ltxsdminInclusive value"10000"/gt
- ltxsdmaxInclusive value"99999"/gt
- lt/xsdrestrictiongt
- lt/xsdsimpleTypegt
- Defining myInteger type whose range of value is
between 10000 and 99999 - minInclusive and maxInclusive are facets that can
be applied to integer type
14Example of Derived Simple Type 2(Regular
Expression)
- ltxsdsimpleType name"SKU"gt
- ltxsdrestriction base"xsdstring"gt
- ltxsdpattern value"\d3-A-Z2"/gt
- lt/xsdrestrictiongt
- lt/xsdsimpleTypegt
- Defining new type called SKU
- pattern is a facet that can be applied to string
- Regular expression
- Three digits followed by a hyphen followed by two
upper-case ASCII letters
15Example of Derived Simple Type 3(Enumeration)
- ltxsdsimpleType name"USState"gt
- ltxsdrestriction base"xsdstring"gt
- ltxsdenumeration value"AK"/gt
- ltxsdenumeration value"AL"/gt
- ltxsdenumeration value"AR"/gt
- lt!-- and so on ... --gt
- lt/xsdrestrictiongt
- lt/xsdsimpleTypegt
- enumeration facet limits a simple type to a set
of distinct values
16Complex Type
- Defined using complexType element
- Typically contain
- element declarations
- element references
- attribute declarations
17complexType Example 1
- ltxsdcomplexType name"USAddress" gt
- ltxsdsequencegt
- ltxsdelement name"name" type"xsdstring" /gt
- ltxsdelement name"street" type"xsdstring" /gt
- ltxsdelement name"city" type"xsdstring" /gt
- ltxsdelement name"state" type"xsdstring" /gt
- ltxsdelement name"zip" type"xsddecimal" /gt
- lt/xsdsequencegt
- ltxsdattribute name"country" type"xsdNMTOKEN"
- use"fixed" value"US"/gt
- lt/xsdcomplexTypegt
- Definition of USAddress type
- It contains 5 element declarations (which are to
be in sequential order) and one attribute
declaration - USAddress definition contains only declarations
involving simple types string, decimal, and
NMTOKEN
18complexType Example 2
- ltxsdcomplexType name"PurchaseOrderType"gt
- ltxsdsequencegt
- ltxsdelement name"shipTo" type"USAddress"/gt
- ltxsdelement name"billTo" type"USAddress"/gt
- ltxsdelement ref"comment" minOccurs"0"/gt
- ltxsdelement name"items" type"Items"/gt
- lt/xsdsequencegt
- ltxsdattribute name"orderDate"
type"xsddate"/gt - lt/xsdcomplexTypegt
19complexType Example 2
- Definition of PurchaseOrder type
- Contains element declarations of complex types,
e.g. USAddress, Items - Contains attribute declaration of predefined
simple types date
20Element vs. Attribute
- Element declarations can reference both simple
types or complex types - All attribute declarations can reference only
simple types - Because they cannot contain other subelements
21ref Attribute
- To use an existing element or attribute rather
than declaring a new element or attribute - Existing element must be global element - an
element that is declared under root element
ltxsdschema xmlnsxsd"http//www.w3.org/2000/08/
XMLSchema"gt ltxsdelement name"purchaseOrder"
type"PurchaseOrderType"/gt ltxsdelement
name"comment" type"xsdstring"/gt ltxsdcomplexTy
pe name"PurchaseOrderType"gt ltxsdsequencegt ltxs
delement name"shipTo" type"USAddress"/gt ltxsd
element name"billTo" type"USAddress"/gt ltxsdel
ement ref"comment" minOccurs"0"/gt ltxsdelement
name"items" type"Items"/gt lt/xsdsequencegt ltxs
dattribute name"orderDate" type"xsddate"/gt lt/x
sdcomplexTypegt
22Occurrences of Elements
- minOccurs
- maxOccurs
- fixed Hannah
- If the element appears, the value must be
Hannah, otherwise the value is set to Hannah
by the parser - default Hannah
- If the element appears, the value is set to what
is specified, otherwise value is set to Hannah
by the parser
23Example
- ltelement nametest typestring
- minOccurs1 maxOccurs1
- minOccurs1 maxOccurs1 fixedHannah
- minOccurs2 maxOccursunbounded
- minOccurs0 maxOccurs1 fixedHannah
- minOccurs0 maxOccurs1 defaultHannah
- minOccurs0 maxOccurs2 defaultHannah
- minOccurs0 maxOccurs0
- gt
24Occurrences of Attributes
- Attributes can occur once or not at all
- use attribute
- required
- optional
- fixed
- default
- value attribute
25Example
- ltattribute nametest typestring
- userequired
- userequired value37
- useoptional
- usefixed, 37
- usedefault value37
- useprohibited
- gt
26Example
ltxsdcomplexType name"USAddress"gt ltxsdsequencegt
ltxsdelement name"name" type"xsdstring"/gt
ltxsdelement name"street" type"xsdstring"/gt .
.. lt/xsdsequencegt ltxsdattribute
name"country" type"xsdNMTOKEN" use"fixed"
value"US"/gt lt/xsdcomplexTypegt
- Appearance of a country attribute is optional
- Its value must be US if it does appear
- If it does not appear, parser will create a
country attribute with value US
27Attributes
- Enumeration
- simpleType element with base attribute
- base attribute specifies the type
ltcomplexType name"ContentsType"gt ltelement
name"Chapter" maxOccurs""gt
ltcomplexTypegt ltelement name"Heading"
type"string" minOccurs"0" /gt ltelement
name"Topic" maxOccurs""gt ltcomplexType
content"string"gt ltattribute
name"subSections" type"integer" /gt
lt/complexTypegt lt/elementgt ltattribute
name"focus" default"Java"gt ltsimpleType
base"string"gt ltenumeration value"XML" /gt
ltenumeration value"Java" /gt
lt/simpleTypegt lt/attributegt lt/complexTypegt
lt/elementgt lt/complexTypegt
28List Type
- Comprised of sequences of atomic (pre-defined)
simple types - Three built-in list types
- NMTOKENS, IDREFS, ENTITIES
- User defined List type
- Derive only from atomic types
- facets
- length, minLength, maxLength, enumeration
29Example of List Type
- Schema
- ltxsdsimpleType name"listOfMyIntType"gt
- ltxsdlist itemType"myInteger"/gt
- lt/xsdsimpleTypegt
- Instance Document
- ltlistOfMyIntgt20003 15037 95977
95945lt/listOfMyIntgt
30Example of List Type
ltxsdsimpleType name"USStateList"gt ltxsdlist
itemType"USState"/gt lt/xsdsimpleTypegt ltxsdsimple
Type name"SixUSStates"gt ltxsdrestriction
base"USStateList"gt ltxsdlength value"6"/gt
lt/xsdrestrictiongt lt/xsdsimpleTypegt ltelement
namesixStates typeSixUSStatesgt
- Define a list of exactly six US states
(SixUSStates), we first define a new list type
called USStateList from USState, and then we
derive SixUSStates by restricting USStateList to
only six items. - ltsixStatesgtPA NY CA NY LA AKlt/sixStatesgt
31Union Type
- Enables an element or attribute value to be one
or more instances of one type drawn from the
union of multiple atomic and list types - facets pattern and enumeration
Union Type for Zipcodes
ltxsdsimpleType name"zipUnion"gt ltxsdunion
memberTypes"USState listOfMyIntType"/gt lt/xsdsimp
leTypegt ltelement namezips typezipUniongt ltz
ipsgtCAlt/zipsgt ltzipsgt95630 95977
95945lt/zipsgt ltzipsgtAKlt/zipsgt
32Explicit Type
- Explicit type
- One in which a name is given to the type
- Element that uses the type is generally defined
in a different section of the file - Object-oriented in that same explicit type is
used as the type for several different elements
lt!-- Type has a name zipUnion --gt ltxsdsimpleType
name"zipUnion"gt ltxsdunion
memberTypes"USState listOfMyIntType"/gt lt/xsdsimp
leTypegt lt!-- zipUnion type is used in other
parts of Schema document --gt ltelement namezips
typezipUniongt ltelement nametheOtherZips
typezipUniongt ltelement nametheThirdZips
typezipUniongt
33Implicit Type
- Implicit type (nameless, anonymous)
- Use when the type is not needed by multiple
elements
ltxsdcomplexType name"Items"gt ltxsdsequencegt
ltxsdelement name"item" minOccurs"0"
maxOccurs"unbounded"gt ltxsdcomplexTypegt
lt!-- Implicit complexType --gt
ltxsdsequencegt ltxsdelement
name"productName" type"xsdstring"/gt
ltxsdelement name"quantity"gt
ltxsdsimpleTypegt lt!-- Implicit simpleType --gt
ltxsdrestriction base"xsdpositiveInteg
er"gt ltxsdmaxExclusive
value"100"/gt lt/xsdrestrictiongt
lt/xsdsimpleTypegt
lt/xsdelementgt ltxsdelement
name"USPrice" type"xsddecimal"/gt
ltxsdelement ref"comment" minOccurs"0"/gt
ltxsdelement name"shipDate" type"xsddate"
minOccurs"0"/gt lt/xsdsequencegt
ltxsdattribute name"partNum" type"SKU"/gt
lt/xsdcomplexTypegt lt/xsdelementgt
lt/xsdsequencegt lt/xsdcomplexTypegt
34Element Content
- How content of an element gets constructed
- Three different ways
- Complex types from simple types
- Mixed content
- Elements mixed with character content
- Empty content
35Complex Types from Simple Types
- ltUSPricegt345.67lt/USPricegt
- ltxsdelement name"USPrice" type"decimal"/gt
- ltinternationalPrice currency"EUR"gt423.46lt/interna
tionalPricegt - ???
- Need to create complexType based on simple type
- Simple type cannot have attributes
- Have to have attribute declaration
- Based on decimal simple type
36Complex Types from a Simple Type
- ltxsdelement name"internationalPrice"gt
- ltxsdcomplexTypegt
- ltxsdsimpleContentgt
- ltxsdextension base"xsddecimal"gt
- ltxsdattribute name"currency
- type"xsdstring" /gt
- lt/xsdextensiongt
- lt/xsdsimpleContentgt
- lt/xsdcomplexTypegt
- lt/xsdelementgt
- simpleContent indicates that the content model of
the new type contains only character data and no
element declaration
37Mixed Content
- Sub-elements mixed with character data
- ltletterBodygt
- ltsalutationgtDear Mr.
- ltnamegtRobert Smithlt/namegt.
- lt/salutationgtYour order of
- ltquantitygt1lt/quantitygt
- ltproductNamegtBaby Monitorlt/productNamegt
- shipped from our warehouse on
- ltshipDategt1999-05-21lt/shipDategt. ....
- lt/letterBodygt
38Mixed Content
- ltxsdelement name"letterBody"gt
- ltxsdcomplexType mixed"true"gt
- ltxsdsequencegt
- ltxsdelement name"salutation"gt
- ltxsdcomplexType mixed"true"gt
- ltxsdsequencegt
- ltxsdelement name"name"
type"xsdstring"/gt - lt/xsdsequencegt
- lt/xsdcomplexTypegt
- lt/xsdelementgt
- ltxsdelement name"quantity"
type"xsdpositiveInteger"/gt - ltxsdelement name"productName"
type"xsdstring"/gt - ltxsdelement name"shipDate"
type"xsddate" minOccurs"0"/gt - lt!-- etc --gt
- lt/xsdsequencegt
- lt/xsdcomplexTypegt
- lt/xsdelementgt
39Empty Content (1)
- Define a type which do not declare any elements
in its content - Types content model is empty
ltinternationalPrice currencyEUR
value345.23/gt ltxsdelement name"international
Price"gt ltxsdcomplexTypegt
ltxsdcomplexContentgt ltxsdrestriction
base"xsdanyType"gt ltxsdattribute
name"currency type"xsdstring"/gt
ltxsdattribute name"value type"xsddecimal"/gt
lt/xsdrestrictiongt lt/xsdcomplexContentgt
lt/xsdcomplexTypegt lt/xsdelementgt
40Empty Content (2)
- complexContent
- To restrict or extend the content model of a
complex type - ltxsdrestriction base"xsdanyType"gt
41Empty Content (3)
- ltxsdelement name"internationalPrice"gt
- ltxsdcomplexTypegt
- ltxsdattribute name"currency
type"xsdstring"/gt - ltxsdattribute name"value type"xsddecimal"/gt
- lt/xsdcomplexTypegt
- lt/xsdelementgt
- A complex type defined without complexContent is
interpreted as shorthand for complex content that
restricts anyType
42anyType
- Base type from which all simple and complex types
are derived - Does not constrain its contents in any way
- Default type when no type is specified
- ltxsdelement name"anything" type"xsdanyType"
/gt - is same as
- ltxsdelement nameanything/gt
- Use more constrained types whenever possible
43Annotation
- Appears at the beginning of most schema
constructions - Can have two sub-elements
- documentation
- For human readable materials
- appInfo
- For tools, stylesheets and other applications
ltxsdelement name"internationalPrice"gt
ltxsdannotationgt ltxsddocumentationgt element
declared with anonymous type
lt/xsddocumentationgt lt/xsdannotationgt
ltxsdcomplexTypegt ltxsdannotationgt
ltxsddocumentationgt empty anonymous type with 2
attributes lt/xsddocumentationgt
lt/xsdannotationgt ltxsdcomplexContentgt
ltxsdrestriction base"xsdanyType"gt
ltxsdattribute name"currency" type"xsdstring"
/gt ltxsdattribute name"value"
type"xsddecimal" /gt lt/xsdrestrictiongt
lt/xsdcomplexContentgt lt/xsdcomplexTypegt lt/xsd
elementgt
44Choice and Group
- choice
- Only one of its children to appear in an instance
- group
- Grouping a group of elements
- Further constraints
- sequence
- all
- Appear zero or once
- In any order
45Choice and Sequence Groups
- ltxsdcomplexType name"PurchaseOrderType"gt
- ltxsdsequencegt
- ltxsdchoicegt
- ltxsdgroup ref"shipAndBill" /gt
- ltxsdelement name"singleUSAddress"
type"USAddress" /gt - lt/xsdchoicegt
- ltxsdelement ref"comment" minOccurs"0"/gt
- ltxsdelement name"items" type"Items" /gt
- lt/xsdsequencegt
- ltxsdattribute name"orderDate" type"xsddate"
/gt - lt/xsdcomplexTypegt
- ltxsdgroup name"shipAndBill"gt
- ltxsdsequencegt
- ltxsdelement name"shipTo" type"USAddress" /gt
- ltxsdelement name"billTo" type"USAddress" /gt
- lt/xsdsequencegt
- lt/xsdgroupgt
46Example of all
- ltxsdcomplexType name"PurchaseOrderType"gt
- ltxsdallgt
- ltxsdelement name"shipTo" type"USAddress"/gt
- ltxsdelement name"billTo" type"USAddress"/gt
- ltxsdelement ref"comment" minOccurs"0"/gt
- ltxsdelement name"items" type"Items" /gt
- lt/xsdallgt
- ltxsdattribute name"orderDate" type"xsddate"
/gt - lt/xsdcomplexTypegt
47Example of attributeGroup
- Define attribute group using attributeGroup
element - Referenced in multiple definitions and
declarations - Improve readability and maintenance
- They have to appear at the end of complex type
definitions
ltxsdattributeGroup name"ItemDelivery"gt
ltxsdattribute name"partNum" type"SKU"/gt
ltxsdattribute name"weightKg" type"xsddecimal"/
gt ltxsdattribute name"shipBy"gt
ltxsdsimpleTypegt ltxsdrestriction
base"xsdstring"gt ltxsdenumeration
value"air"/gt ltxsdenumeration
value"land"/gt ltxsdenumeration
value"any"/gt lt/xsdrestrictiongt
lt/xsdsimpleTypegt lt/xsdattributegt lt/xsdattribu
teGroupgt lt!-- attributeGroup replaces
individual declarations --gt ltxsdattributeGroup
ref"ItemDelivery"/gt
48Schema Namespaces
- Two namespaces to deal with
- Namespace for XML Schema document itself
- http//www.w3.org/2000/08/XMLSchema
- In XML Schema document, this is set as default
namespace - Prefix string convention is schema
- Namespace for XML document being constrained
- targetNamespace
- Indicating which namespace is a target namespace
- Element does not need to be prefixed
- Different from DTD
49Schema Namespaces
- Namespaces in XML rules and definitions
- Elements and attributes that are in namespaces
are called qualified. - All unprefixed attributes are unqualified.
- All prefixed elements are qualified.
- Unprefixed elements may or may not be qualified.
They are qualified if they are in a default
namespace. - Each schema has a target namespace.
- Each schema can define elements and attributes in
its target namespace. - A schema can also define unqualified attributes
of elements in its target namespace. - A schema can also define unqualified child
elements of elements in its target namespace.
Unqualified child elements are called local
elements. This is a very bad idea! - A schema may not define elements and attributes
in namespaces other than the target namespace
i.e., for each namespace there must be at least
one schema. - Schemas can reference global elements and
attributes defined in other schemas by importing
the schema with xsdimport and referencing the
global elements and attributes defined therein.
50XML Document and XML Schema
- XML document (Instance document) is not required
to make a reference to XML schema - Validator has to have access to XML schema
- Hints of where to get schema document
- schemaLocation
- Validator can ignore these hints
51schemaLocation
- In an instance document, the attribute
xsischemaLocation - ltpurchaseReport
- xmlns"http//www.example.com/Report"
- xmlnsxsi"http//www.w3.org/1999/XMLSchema-insta
nce" - xsischemaLocation"http//www.example.com/Report
- http//www.example.com/Report.xsd"
- period"P3M" periodEnding"1999-12-31"gt
- lt!-- etc --gt
- lt/purchaseReportgt
52Whitespace
- Determines what the validator should do with
white space before validating the value. - Three possible values
- preserve The white space in the input document
is left unchanged. - replace Each tab, carriage return and linefeed
is replaced with a single space. - collapse Each tab, carriage return and linefeed
is replaced with a single space. Furthermore,
after this replacement is performed, all runs of
multiple spaces are condensed to a single space.
Leading and trailing white space is deleted. - Applies to string, normalizedString and token
type items. - Per XML 1.0, white space in attributes is
normalized irregardless of the schema.
53Whitespace
- For example, to say that white space should be
collapsed in all names and titles
lt?xml version"1.0"?gt ltxsdschema
xmlnsxsd"http//www.w3.org/2001/XMLSchema"gt
ltxsdelement name"SONG" type"songType"/gt
ltxsdsimpleType name"CollapsedString"gt
ltxsdrestriction base"xsdstring"gt
ltxsdwhiteSpace value"collapse"/gt
lt/xsdrestrictiongt lt/xsdsimpleTypegt
ltxsdcomplexType name"songType"gt
ltxsdsequencegt ltxsdelement name"TITLE"
type"CollapsedString"/gt ltxsdelement
name"COMPOSER" type"CollapsedString"
maxOccurs"unbounded"/gt ltxsdelement
name"PRODUCER" type"CollapsedString"
minOccurs"0" maxOccurs"unbounded"/gt
ltxsdelement name"PUBLISHER" type"CollapsedStrin
g" minOccurs"0"/gt ltxsdelement
name"LENGTH" type"xsdduration"/gt
ltxsdelement name"YEAR" type"xsdgYear"/gt
ltxsdelement name"ARTIST"
type"CollapsedString"
maxOccurs"unbounded"/gt lt/xsdsequencegt
lt/xsdcomplexTypegt lt/xsdschemagt
54A Document with Attributes and Element Content
lt?xml version"1.0"?gt ltSONG xmlnsxsi"http//www.
w3.org/2001/XMLSchema-instance"
xsinoNamespaceSchemaLocation"nested_song.xsd"gt
ltTITLEgtHot Coplt/TITLEgt ltPHOTO ALT"Victor
Willis in Cop Outfit" WIDTH"100"
HEIGHT"200"/gt ltCOMPOSERgt ltNAMEgt
ltGIVENgtJacqueslt/GIVENgt ltFAMILYgtMoralilt/FAMIL
Ygt lt/NAMEgt lt/COMPOSERgt ltCOMPOSERgt
ltNAMEgt ltGIVENgtHenrilt/GIVENgt
ltFAMILYgtBelololt/FAMILYgt lt/NAMEgt
lt/COMPOSERgt ltPRODUCERgt ltNAMEgt
ltGIVENgtJacqueslt/GIVENgt ltFAMILYgtMoralilt/FAMIL
Ygt lt/NAMEgt lt/PRODUCERgt ltPUBLISHERgtPolyGram
Recordslt/PUBLISHERgt ltYEARgt1978lt/YEARgt
ltARTISTgtVillage Peoplelt/ARTISTgt lt/SONGgt
55Declaring Complex Types (1)
ltxsdschema xmlnsxsd"http//www.w3.org/2001/XMLS
chema"gt ltxsdelement name"SONG"
type"SongType"/gt ltxsdcomplexType
name"ComposerType"gt ltxsdsequencegt
ltxsdelement name"NAME"gt
ltxsdcomplexTypegt ltxsdsequencegt
ltxsdelement name"GIVEN"
type"xsdstring"/gt ltxsdelement
name"FAMILY" type"xsdstring"/gt
lt/xsdsequencegt lt/xsdcomplexTypegt
lt/xsdelementgt lt/xsdsequencegt
lt/xsdcomplexTypegt ltxsdcomplexType
name"ProducerType"gt ltxsdsequencegt
ltxsdelement name"NAME"gt
ltxsdcomplexTypegt ltxsdsequencegt
ltxsdelement name"GIVEN"
type"xsdstring"/gt ltxsdelement
name"FAMILY" type"xsdstring"/gt
lt/xsdsequencegt lt/xsdcomplexTypegt
lt/xsdelementgt lt/xsdsequencegt
lt/xsdcomplexTypegt
56Declaring Complex Types (2)
ltxsdcomplexType name"PhotoType"gt
ltxsdcomplexContentgt ltxsdrestriction
base"xsdanyType"gt ltxsdattribute
name"ALT" type"xsdstring"/gt
ltxsdattribute name"WIDTH" type"xsdnonNegative
Integer"/gt ltxsdattribute name"HEIGHT"
type"xsdnonNegativeInteger"/gt
lt/xsdrestrictiongt lt/xsdcomplexContentgt
lt/xsdcomplexTypegt ltxsdcomplexType
name"SongType"gt ltxsdsequencegt
ltxsdelement name"TITLE" type"xsdstring"/gt
ltxsdelement name"PHOTO"
type"PhotoType" minOccurs"0"/gt
ltxsdelement name"COMPOSER" type"ComposerType"
maxOccurs"unbounded"/gt
ltxsdelement name"PRODUCER" type"ProducerType"
minOccurs"0" maxOccurs"unbounded"/gt
ltxsdelement name"PUBLISHER"
type"xsdstring" minOccurs"0"/gt
ltxsdelement name"YEAR" type"xsdgYear"/gt
ltxsdelement name"ARTIST" type"xsdstring"
maxOccurs"unbounded"/gt
lt/xsdsequencegt lt/xsdcomplexTypegt lt/xsdschemagt
57Sharing Content Models
- PRODUCER and COMPOSER are really the same type.
ltxsdelement name"SONG" type"SongType"/gt
ltxsdcomplexType name"PersonType"gt
ltxsdsequencegt ltxsdelement name"NAME"gt
ltxsdcomplexTypegt ltxsdsequencegt
ltxsdelement name"GIVEN"
type"xsdstring"/gt ltxsdelement
name"FAMILY" type"xsdstring"/gt
lt/xsdsequencegt lt/xsdcomplexTypegt
lt/xsdelementgt lt/xsdsequencegt
lt/xsdcomplexTypegt ltxsdcomplexType
name"SongType"gt ltxsdsequencegt
ltxsdelement name"TITLE" type"xsdstring"/gt
ltxsdelement name"PHOTO"
type"PhotoType" minOccurs"0"/gt
ltxsdelement name"COMPOSER" type"PersonType"
maxOccurs"unbounded"/gt ltxsdelement
name"PRODUCER" type"PersonType"
minOccurs"0" maxOccurs"unbounded"/gt
ltxsdelement name"PUBLISHER" type"xsdstring"
minOccurs"0"/gt ltxsdelement
name"YEAR" type"xsdgYear"/gt
ltxsdelement name"ARTIST" type"xsdstring"
maxOccurs"unbounded"/gt lt/xsdsequencegt
lt/xsdcomplexTypegt
58When Order Doesnt Matter!
lt?xml version"1.0"?gt ltSONG xmlnsxsi"http//www.
w3.org/2001/XMLSchema-instance"
xsinoNamespaceSchemaLocation"unordered_song.xsd"
gt ltTITLEgtHot Coplt/TITLEgt ltPHOTO ALT"Victor
Willis in Cop Outfit" WIDTH"100" HEIGHT"200"/gt
ltCOMPOSERgt ltNAMEgtltFAMILYgtMoralilt/FAMILYgt
ltGIVENgtJacqueslt/GIVENgtlt/NAMEgt lt/COMPOSERgt
ltCOMPOSERgt ltNAMEgtltGIVENgtHenrilt/GIVENgt
ltFAMILYgtBelololt/FAMILYgtlt/NAMEgt lt/COMPOSERgt
ltPRODUCERgt ltNAMEgtltGIVENgtJacqueslt/GIVENgt
ltFAMILYgtMoralilt/FAMILYgtlt/NAMEgt lt/PRODUCERgt
ltPUBLISHERgtPolyGram Recordslt/PUBLISHERgt
ltYEARgt1978lt/YEARgt ltARTISTgtVillage
Peoplelt/ARTISTgt lt/SONGgt
59XML Schema the Disadvantages
- Very lengthy and hard-to-read specifications.
- Difficult to grasp some of the concepts if you
have no background in Object Oriented languages. - Does little to bridge the gap between the
SGML/document world and the XML/data world. - Schemas are more verbose and complex than DTDs.
- Attempts to solve too many problems at once too
complex.
60Summary
- Status
- Motivation
- Vocabularies
- element, attributes
- simpleType and complexType
- minOccurs, maxOccurs
- enumeration
- choice, group, all
- list, union
- http//www.w3.org/TR/xmlschema-0/