SDPL 2005 Notes 2.5: XML Schemas 1 2.5 XML Schemas 2.5 XML Schemas Short introduction to XML Schema Short introduction to XML Schema – W3C Recommendation, W3C Recommendation, 1 1 st st Ed. May, 2001; 2 Ed. May, 2001; 2 nd nd Ed. Oct, 2004: Ed. Oct, 2004: » XML Schema Part 0: Primer (readable non- XML Schema Part 0: Primer (readable non- normative introduction; Recommended) normative introduction; Recommended) » XML Schema Part 1: Structures XML Schema Part 1: Structures » XML Schema Part 2: Datatypes XML Schema Part 2: Datatypes – Also started (but didn't lead Also started (but didn't lead anywhere?): anywhere?): » XML Schema: Formal Description, W3C Working XML Schema: Formal Description, W3C Working Draft, September 2001 Draft, September 2001
22
Embed
SDPL 2005Notes 2.5: XML Schemas1 2.5 XML Schemas n Short introduction to XML Schema –W3C Recommendation, 1 st Ed. May, 2001; 2 nd Ed. Oct, 2004: »XML Schema.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
SDPL 2005 Notes 2.5: XML Schemas 1
2.5 XML Schemas2.5 XML Schemas
Short introduction to XML SchemaShort introduction to XML Schema– W3C Recommendation,W3C Recommendation,
11stst Ed. May, 2001; 2 Ed. May, 2001; 2ndnd Ed. Oct, 2004: Ed. Oct, 2004:» XML Schema Part 0: Primer (readable non-XML Schema Part 0: Primer (readable non-
» XML Schema Part 1: StructuresXML Schema Part 1: Structures
» XML Schema Part 2: DatatypesXML Schema Part 2: Datatypes
– Also started (but didn't lead anywhere?):Also started (but didn't lead anywhere?):» XML Schema: Formal Description, W3C XML Schema: Formal Description, W3C
Working Draft, September 2001Working Draft, September 2001
SDPL 2005 Notes 2.5: XML Schemas 2
Schema terminologySchema terminology
Schema Schema ((kaaviokaavio): a formal description for the ): a formal description for the structure and allowed contents of data structure and allowed contents of data (esp. in databases)(esp. in databases)
““XML Schema” is often used for each of … XML Schema” is often used for each of … 1.1. XML SchemaXML Schema, the W3C Rec. that defines … , the W3C Rec. that defines … 2.2. XML Schema Definition LanguageXML Schema Definition Language ( (XSDLXSDL), ),
an XML-based markup language for an XML-based markup language for expressing ... expressing ... 3.3. schema documentsschema documents, each of which describes a , each of which describes a schema (schema ( DTD) for a set of XML document instances DTD) for a set of XML document instances
(This may cause some confusion!)(This may cause some confusion!)
SDPL 2005 Notes 2.5: XML Schemas 3
Advantages of XSDL (1)Advantages of XSDL (1)
XML syntaxXML syntax– schema documents easier to manipulate by schema documents easier to manipulate by
programs (than the special DTD syntax)programs (than the special DTD syntax) Compatibility with namespacesCompatibility with namespaces
– can validate documents using declarations from can validate documents using declarations from multiple sourcesmultiple sources
NB: all simple values in NB: all simple values in documents documents stringsstrings
**CDATACDATA
**
**
**
**
**
**
**
**
*: XML attribute *: XML attribute typestypes
SDPL 2005 Notes 2.5: XML Schemas 5
Advantages of XSDL (2)Advantages of XSDL (2)
Element names and Element names and content typescontent types independent; Compare with independent; Compare with – DTDs: 1-to-1 correspondence btw. element type DTDs: 1-to-1 correspondence btw. element type
names and their content models names and their content models – CFGs: 1-to-1 correspondence btw. nonterminals CFGs: 1-to-1 correspondence btw. nonterminals
and their productionsand their productions For example, could define For example, could define titlestitles
– of people as “Mr.”/”Mrs.”/”Ms.”, andof people as “Mr.”/”Mrs.”/”Ms.”, and– of chapters as stringsof chapters as strings
SDPL 2005 Notes 2.5: XML Schemas 6
Advantages of XSDL (3)Advantages of XSDL (3)
Ability to specify uniqueness and keys Ability to specify uniqueness and keys within selected parts of the documentwithin selected parts of the document– for example, that for example, that titletitless of chapters should be of chapters should be
unique; or key attributes of relationsunique; or key attributes of relations– uses XPathuses XPath
Support for schema documentation Support for schema documentation – element element annotationannotation with sub-elements with sub-elements
documentation documentation (for human readers) and(for human readers) andappInfo appInfo (for applications)(for applications)
SDPL 2005 Notes 2.5: XML Schemas 7
Disadvantages of XSDLDisadvantages of XSDL
Complexity of XSDL (esp. of Rec. Part 1!) vs. added Complexity of XSDL (esp. of Rec. Part 1!) vs. added power power – > a long learning curve> a long learning curve– > possible rejection by users> possible rejection by users
Possible immaturity of implementations (?)Possible immaturity of implementations (?)– W3C XML Schema Web site mentions ~40 tools or W3C XML Schema Web site mentions ~40 tools or
processors (processors (http://www.w3.org/XML/Schema#Tools, March http://www.w3.org/XML/Schema#Tools, March 2004)2004)
– Open-source Apache XML parsers (Xerces C++ 2.0 and Open-source Apache XML parsers (Xerces C++ 2.0 and Xerces 2 Java) claim full XML Schema supportXerces 2 Java) claim full XML Schema support
Alternative schema languages have been Alternative schema languages have been suggested, too (See later)suggested, too (See later)
SDPL 2005 Notes 2.5: XML Schemas 8
XSDL through ExampleXSDL through Example
– Next: walk-through of an XML schema exampleNext: walk-through of an XML schema example– from Chapter 2 of the XML Schema Primerfrom Chapter 2 of the XML Schema Primer
– Consider modelling purchase orders like below:Consider modelling purchase orders like below:
The Purchase Order Schema (5/5)The Purchase Order Schema (5/5)
<!-- Type for Stock Keeping Units, <!-- Type for Stock Keeping Units, (codes for identifying products): --> (codes for identifying products): -->
<xs:simpleType name="SKU"> <xs:simpleType name="SKU"> <xs:restriction base="xs:string"><xs:restriction base="xs:string"><!-- defined by a regular expr: --> <!-- defined by a regular expr: --> <xs:pattern value="\d{3}-[A-Z]{2}" /> <xs:pattern value="\d{3}-[A-Z]{2}" />
Element content of Element content of complexType complexType can be can be regulated using regulated using – group elements group elements sequencesequence, , choice choice and and allall,,
and and
– occurrence constraint attributes occurrence constraint attributes minOccurs minOccurs and and maxOccursmaxOccurs
Elements Elements sequencesequence and and choice choice correspond to catenation and alternation correspond to catenation and alternation ( | ) in ( | ) in regularregular expressions expressions
Unordered content: the Unordered content: the allall group group
XSDL XSDL all all group is a restricted version of group is a restricted version of the &-connector in SGMLthe &-connector in SGML– E1 & … & En allows sequences corresponding E1 & … & En allows sequences corresponding
to any permutation of E1, …, Ento any permutation of E1, …, En
XSDL restrictions to XSDL restrictions to all:all:– cannot be combined with other content model cannot be combined with other content model
groupsgroups» can have only (non-iterative) elements as childrencan have only (non-iterative) elements as children
– can be optional (can be optional (minOccurs=0minOccurs=0) but not ) but not repeated (repeated (maxOccurs=1maxOccurs=1))
SDPL 2005 Notes 2.5: XML Schemas 20
The The allall group: An example group: An example
For example For example <xs:<xs:allall> > <xs:element name=”A” /> <xs:element name=”A” /> <xs:element name=”<xs:element name=”BB” /> ” /> <xs:element name=”<xs:element name=”CC” ” minminOccurs=’Occurs=’00’ />’ /></xs:</xs:allall>>
accepts the following element sequences:accepts the following element sequences:
A B C; A C B; B A C; B C A; C A B; C B A;A B C; A C B; B A C; B C A; C A B; C B A;A B; and B A;A B; and B A;
SDPL 2005 Notes 2.5: XML Schemas 21
XML Schema: SummaryXML Schema: Summary
XSDL: an XML-based grammar XSDL: an XML-based grammar formalismformalism– W3C RecommendationW3C Recommendation– Alternative to the DTD formalismAlternative to the DTD formalism– more powerful than DTDs (esp. content more powerful than DTDs (esp. content
and attribute datatypes)and attribute datatypes) Rather well accepted in XML industryRather well accepted in XML industry
– e.g., to describe messages btw e.g., to describe messages btw Web servicesWeb services; ; WSDL (Web Services Description Language, Vers. WSDL (Web Services Description Language, Vers. 2.0, W3C Working Draft, 8/04) requires XSDL 2.0, W3C Working Draft, 8/04) requires XSDL support of processorssupport of processors
SDPL 2005 Notes 2.5: XML Schemas 22
XML Schema: Future?XML Schema: Future?
XSDL has also been criticizedXSDL has also been criticized– for overwhelming complexity vs. for overwhelming complexity vs.
relatively little added power relatively little added power – other XML-based schema languages other XML-based schema languages
proposed and implemented, too proposed and implemented, too – For example, RELAX NGFor example, RELAX NG
» Draft international ISO/IEC standard Draft international ISO/IEC standard » Simpler and with a rigorous formal base, and Simpler and with a rigorous formal base, and
more powerful at certain places (e.g. more powerful at certain places (e.g. dependencies of attributes, unordered dependencies of attributes, unordered content)content)