1. Schema
ďŽ Schemas
ď¨specify the structure of an XML document
ď¨constraints on its content
ďŽ This is also the purpose of a DTD
ď¨schema does it better
ď¨syntax is XML
ď¨can use existing XML tools
2. Schema
ďŽ What you can't do with DTD's
ď¨constrain the #PCDATA e.g.
ďŽ a telephone number
ďŽ a price
ďŽ a single word
ď¨precisely constrain repetition
ďŽ up to three children on a family ticket
ď¨a precise selection of elements
ďŽ in any combination or permutation
3. Schema
ďŽ XML is a meta-language for defining tag
languages
ďŽ A schema is a formal specification (in
XML) of the grammar for one language
ď¨useful for validating content & interchange
ďŽ XML Schema is a language for writing the
specifications
4. Schemas
⢠Common Vocabularies
⢠Shared Applications
⢠Network effect
⢠Formal Sets of Rules
⢠Machine-based XML processing
⢠Not human-based document processing
⢠Building Contracts
⢠Core rules for a series of transactions
5. Schemas
⢠DTDs
⢠good at describing documents
⢠can't manage complex data structures
⢠syntax is not extensible
⢠available tools won't work
6. Schemas
ďŽ Schemas build on primitive types
ď¨integers, floating point, strings, dates
ďŽ Types can be based on other types
ď¨aggregations
ď¨specifications
ď¨restrictions
ď¨equivalences
ďŽ Distinction between types and elements
7. Schemas
ďŽ Schema building is very like
ď¨OO data design
ď¨E-R diagrams
ďŽ Schemas may be complex compared to
the documents
ď¨because humans 'intuitively understand' tag
names
8. Schema Standards
⢠XML Schema (current W3C standard)
⢠large, full-featured, unimplemented
⢠XML-Data
⢠early contender, supported by Microsoft
⢠reduced set of XML-Data is part of IE5.
⢠DCD
⢠joint creation of Microsoft and IBM
⢠simpler version of XML-Data
9. Schema Standards
⢠SOX
⢠XML structures via OO-inheritance
⢠Schematron
⢠uses XSLT for schemas
⢠DSD
⢠like Schematron with simpler XML syntax
⢠RELAX
⢠based on hedge automata theory
⢠much simpler than XML Schema
11. Schema Problems
ďŽ Legal implications of schemas as
contracts
ď¨Eskimo Snow and Scottish Rain:
Legal Considerations of Schema Design
ď¨ http://www.w3.org/TR/md-policy-design
ď¨syntactic operability with semantic fault
ď¨occurs because DTDs and schemas mix
ďŽ syntax
ďŽ semantics
12. Schema Problems
⢠W3C standard "XML Schemas"
⢠Too big, too complex
⢠XML 1.0 spec = 30 pages, Schemas >200
⢠Too much, too soon
⢠it isn't clear that many developers are sure
what to do with this enormous toolkit today.
⢠Competitors
13. Defining A Schema (IE5)
ďŽ Take an example XML document instance
<?xml version="1.0"?>
<pizzaOrder>
<when>18:04:30</when>
<cost>8.75</cost>
<pizza>Hot n Spicy</pizza>
</pizzaOrder>
14. Defining A Schema (IE5)
ďŽ First declare that it uses a schema
definition via the default namespace
<?xml version="1.0"?
xmlns="x-schema:pizzaOrderSchema.xml">
<pizzaOrder>
<when>18:04:30</when>
<cost>8.75</cost>
<pizza>Hot n Spicy</pizza>
</pizzaOrder>
15. Defining a Schema (IE5)
ďŽ Now create an outline schema
<Schema
xmlns="urn:schemas-microsoft-com:xml-data">
...
</Schema>
ďŽ ie an XML document from the schema
language namespace
16. Defining a Schema (IE5)
ďŽ First we declare the kinds of elements we
have
<Schema xmlns="urn:schemas-microsoft-com:xml-data">
<ElementType name="when"/>
<ElementType name="cost"/>
<ElementType name="pizza"/>
<ElementType name="pizzaOrder"/>
</Schema>
18. Defining a Schema (IE5)
ďŽ and then content model
<Schema xmlns="urn:schemas-microsoft-com:xml-data">
<ElementType name="when" content="textOnly" />
<ElementType name="cost" content="textOnly"/>
<ElementType name="pizza" content="textOnly"/>
<ElementType name="pizzaOrder" content="eltOnly">
<element type="when"/>
<element type="cost"/>
<element type="pizza"/>
</ElementType>
</Schema>
19. Defining a Schema (IE5)
ďŽ and even the content model for text
<Schema xmlns="urn:schemas-microsoft-com:xml-data">
<ElementType name="when" content="textOnly"
type="time"/>
<ElementType name="cost" content="textOnly"
type="float"/>
<ElementType name="pizza" content="textOnly"/>
<ElementType name="pizzaOrder" content="eltOnly">
<element type="when"/>
<element type="cost"/>
<element type="pizza"/>
...
20. Defining a Schema (IE5)
ďŽ But that requires another namespace
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="when" content="textOnly"
dt:type="time"/>
<ElementType name="cost" content="textOnly"
dt:type="float"/>
<ElementType name="pizza" content="textOnly"/>
<ElementType name="pizzaOrder" content="eltOnly">
<element type="when"/>
<element type="cost"/>
...
21. Schema Components
ďŽ Schemas build on the declarations and
usage of elements and attributes
ď¨ ElementType elements declare a kind of element
ď¨ AttributeType elements declare a kind of attribute
ď¨ element elements show the use of an element within
the context of another element
ď¨ attribute elements show the use of an attribute on an
element
22. Schema Components
ďŽ Various attributes specify the allowable
properties each element or attribute
ď¨ model specifies whether the element may contain
'foreign' elements, not specified in the schema
ď¨ minOccurs and maxOccurs put lower- and upper-
bounds on the repetition of an element
ď¨ order specifies whether subelements must appear in
the order specified, or whether only a single
subelement can be chosen
ď¨ required states that an attribute must be present
ď¨ default gives a default value for a missing attribute
23. Schema Data Types
ďŽ Microsoft's Schema provides 23 built-in
data types to which textual content can
conform
ď¨various numeric types (float, ints)
ď¨date, time, urn, uuid, char, hex, boolean and
blob
ďŽ No derived / extended types are allowed
ďŽ Separate namespace labels data vocab
24. Using Data Types
ďŽ A node's validated data type is directly
accessible within the IE DOM
ď¨DOMelement.nodeTypedValue
ď¨instead of .nodeValue or .text
ďŽ A node's schema definition is available
ď¨DOMElement.definition property
see
weather
.html