3. Outline
Overview
n
xml.apache.org project
n
Business / Technical motivation for XML
n
Schema
Coverage of Key XML Schema Features
n
Alternative Schema Languages
n
4. Apache Software Foundation
Non-profit foundation
n
volunteers
n
Open Source Software
n
Apache License
n
Not viral like GPL
n
Commercial Use is fine
n
Projects
n
Web Server
n
jakarta.apache.org
n
JSP, Servlets, Ant, Struts, Server Frameworks
n
xml.apache.org
n
5. xml.apache.org
Part of the Apache Software Foundation
n
Open Source XML processing
n
components
XML Parser [Xerces] (Java, C++, Perl)
n
XSLT processor [Xalan] (Java, C++)
n
XSL Formatting Objects [FOP]
n
SVG [Batik]
n
Cocoon
n
SOAP [Apache-SOAP / Axis]
n
6. Business Motivation
XML is a language of agreements
n
We needed a way to specify those
n
agreements in more detail – raises the
level of discourse between applications
We needed a way for machines to be
n
able to do more with those agreements
7. Technical Motivation
Three major needs leading up to XML
n
Schema
Strong data typing of element content and
n
attributes – push more validation into the
XML infrastructure
Integration of namespaces into grammars
n
Use of XML syntax to describe the
n
grammar
8. When would you use Schema?
You have rich data types [typing]
n
You need open content models
n
[wildcards]
You need to combine data from multiple
n
organzations [namespaces]
You are mapping from database
n
[uniqueness]
10. XML Schema Specification
W3C Recommendation as of 5/2/2001
n
Three documents:
n
XML Schema Part 0: Primer
n
XML Schema Part 1: Structures
n
XML Schema Part 2: Datatypes
n
Support in Xerces-J 1.4+
n
11. Type System Design Features
Elements and attributes have explicit
n
types
Types can be defined independently
n
Definitions
n
Global
n
Local/Anonymous
n
12. Two kinds of types
Simple types
n
describe character data
n
Complex types
n
Can have attributes
n
Can have content models (elements)
n
13. Example of simple type
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
<element name='withdraw' type=quot;integer“/>
</schema>
14. Simple types
Lexical Space
n
Value Space
n
Facets
n
Primitive built-in types
n
XML 1.0 types
n
String, boolean, numbers, dates, times
n
15. Creating new simple types
Restriction
n
<schema
n
xmlns='http://www.w3.org/2001/XMLSchema'>
<element name='withdraw'>
<simpleType>
<restriction base='integer'>
<minInclusive value=quot;0quot;/>
</restriction>
</simpleType>
</element>
</schema>
Some built in types are restrictions of
n
primitive types
16. Facets
Numeric range restriction
n
Miniumum and maximum
n
Inclusive / exclusive
n
Enumeration
n
Explicit enumeration
n
Pattern – regular expressions
n
Constrains strings
n
17. Atomic vs non-Atomic types
Atomic Types
n
List
n
<schema
n
xmlns='http://www.w3.org/2001/XMLSchema'>
<element name='friends'>
<simpleType>
<list itemType='string'/>
</simpleType>
</element>
</schema>
Union
n
18. Example of complex type
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
<element name='withdraw'>
<complexType>
<simpleContent>
<extension base='integer'>
<attribute name='currency‘ type='string'
default='us'/>
</extension>
</simpleContent>
</complexType>
</element>
</schema>
19. Complex types
Carry attributes
n
Can have child element content
n
Can be derived from simple types
n
20. Content Models
Complex types have content models to
n
describe nested elements, etc.
Content Model types
n
SimpleContent – just content
n
element only content
n
ComplexContent – type derivation
n
Mixed Content – elements and content
n
Empty content
n
21. Element Only Content
<schema
n
xmlns=‘http://www.w3.org/2001/XMLSchema’>
<complexType name=‘person’>
<sequence>
<element name=‘name’ type=‘string’/>
<element name=‘age’ type=‘positiveInteger’>
</sequence>
</complexType>
</schema>
22. Compositors
Three compositors
n
<sequence>
n
<choice>
n
<all>
n
23. Mixed Content
Stricter than XML 1.0 – order and
n
number of child elements counts
Attribute on complexType or
n
complexContent
26. minOccurs/maxOccurs
How do I specify how many times an element
n
occurs?
<schema
xmlns='http://www.w3.org/2001/XMLSchema' >
<complexType name=‘friend’>
<element name=‘lastName’ type=‘string’/>
<element name=‘firstName’ type=‘string’/>
</complexType>
<element name=‘friends’>
<sequence>
<element name=‘friend’ minOccurs=‘0’
maxOccurs=‘unbounded’/>
</sequence>
</schema>
27. Attributes
Use any simple type
n
<attribute name=‘delayed’ type=‘boolean’
use=‘optional’ default=‘false’/>
<attribute name=‘ranking’
type=‘positiveInteger’
use=‘required’/>
28. ComplexType Extension
Add to end of type
n
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
<complexType name='personType'>
<sequence>
<element name='name' type='string'/>
<element name='father' type='string'/>
</sequence>
</complexType>
34. Modularity vs inheritance
Kohsuke Kawaguchi
n
Model groups simulate inheritance,
n
since they nest
Restriction forces you to write it all out,
n
so this is a model group as well
Checking model groups is much easier
n
than checking inheritance
35. Include
For physical modularity of a schema
n
Definitions in the same target
n
namespace
<include
n
schemaLocation=‘http://www.schemas.com/fragment
.xsd’/>
36. Target Namespaces
To put a set of definitions into a
n
namespace…
<schema xmlns='http://www.w3.org/2001/XMLSchema'
targetNamespace='http://www.sauria.com/Schemas/Tutori
al/target'>
<element name='withdraw' type=quot;integer“/>
</schema>
37. Import
Mix types from different namespaces
n
Simple types can be used
n
Must be global
n
Complex types can be used
n
Named, global types only
n
Import element must appear first in
n
schema
Can also import and redefine imported
n
items
40. XML Schema Instance NS
XML Schema Instance Namespace
n
URI is
n
http://www.w3.org/2001/XMLSchema-instance
Prefix is xsi
n
type
n
Force an element to be associated with a
n
particular type
<person xsi:type=‘parent’/>
n
nil
n
For values that can be nil/null, specify the nil
n
value.
42. Wildcards
How do I leave a schema open for
n
extension?
“Any element from namespace x,y or z”
n
“Any element from a namespace
n
besides this one”
“Any element from a schema in no
n
namespace”
“Any element from any namespace”
n
Similarly for attributes
n
45. Annotation
A standard way to document schemas
n
<documentation> – for humans
n
<appinfo> – for programs
n
<annotation>
n
<documentation>text here
</documentation>
<appinfo>
<rdf-loc>http://www.schemas.com/rdf
</rdf-loc>
</appinfo>
</annotation>
46. Uniqueness
“I want to ensure that the value of an
n
element <foo> is unique”
In what scope? There may be two
n
elements named <foo>, each children of
two different elements
Specify the scope using XPath
n
55. Alternatives to XML Schema
Some people feel XML Schema is too
n
complicated
Relax => TREX => Relax NG
n
Relax (Murata Makoto)
n
Relax Verifier
n
TREX (James Clark)
n
JTREX
n
Relax NG (OASIS)
n
Jing
n
56. Relax NG
Uses XML Instance Syntax
n
Supports namespaces
n
Much simpler than XML Schema
n
More orthogonal than XML Schema
n
Can use XML Schema datatypes
n
Doesn’t support uniqueness, inheritance
n
57. Relax NG Example
<element name=‘book’ dataTypeLibrary=‘…’>
n
<element name=‘title’>
<data type=‘string’>
</element>
<element name=‘quantity’>
<data type=‘integer’>
</element>
</element>
<element name=‘books’>
<oneOrMore>
<ref name=‘book’/>
</oneOrMore>
</element>
58. Thank You!
http://xml.apache.org
n
twl@apache.org
n