Presentation on theme: "1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft: www.w3.org/TR/2001/REC-xmlschema-1-20010502."— Presentation transcript:
1 Web Data Management XML Schema
2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
3 XML Schemas generalizes DTDs uses XML syntax two documents: structure and datatypes –http://www.w3.org/TR/xmlschema-1 –http://www.w3.org/TR/xmlschema-2 XML-Schema is very complex –often criticized –some alternative proposals
9 Says that the elements declared in this schema (BookCatalogue, Book, Title, Author, Date, ISBN, Publisher) are to go in this namespace
10 BookCatalogue Book Title Author Date ISBN Publisher (targetNamespace) Publishing Namespace (targetNamespace)
11 This is referencing a Book element declaration. The Book in what namespace? Since there is no namespace qualifier it is referencing the Book element in the default namespace, which is the targetNamespace! The default namespace is which is the targetNamespace!
12 This is a directive to instance documents which use this schema: Any elements used by the instance document which were declared by this schema must be namespace qualified by the namespace specified by targetNamespace.
13 Referencing a schema in an XML instance document My Life and Times Paul McCartney July, McMillin Publishing First, using a default namespace declaration, tell the schema-validator that all of the elements used in this instance document come from the publishing namespace. 2. Second, with schemaLocation tell the schema-validator that the namespace is defined in BookCatalogue.xsd. 3. Third, tell the schema-validator that schemaLocation attribute we are using is the one in the schema instance namespace.
14 Referencing a schema in an XML instance document BookCatalogue.xml BookCatalogue.xsd targetNamespace="A" schemaLocation="A BookCatalogue.xsd" - defines elements in namespace A - uses elements from namespace A
15 Note multiple levels of checking BookCatalogue.xmlBookCatalogue.xsd XMLSchema.xsd (schema-for-schemas) Validate that the xml document conforms to the rules described in BookCatalogue.xsd Validate that BookCatalogue.xsd is a valid schema document, i.e., it conforms to the rules described in the schema-for-schemas
16 Default Value for minOccurs and maxOccurs The default value for minOccurs is "1" The default value for maxOccurs is "1" Equivalent!
17 Qualify XMLSchema, Default targetNamespace In the last example, we explicitly qualified all elements from the XML Schema namespace. The targetNamespace was the default namespace. BookCatalogue Book Title Author Date ISBN Publisher element annotation documentation complexType schema sequence
18 Default XMLSchema, Qualify targetNamespace Alternatively (equivalently), we can design our schema so that XMLSchema is the default namespace. BookCatalogue Book Title Author Date ISBN Publisher element annotation documentation complexType schema sequence
19 Here we are referencing a Book element. Where is that Book element defined? In what namespace? The pub: prefix indicates what namespace this element is in. pub: has been set to be the same as the targetNamespace.
20 "pub" References the targetNamespace BookCatalogue Book Title Author Date ISBN Publisher (targetNamespace) element annotation documentation complexType schema sequence pub
21 Alternate Schema In the previous examples we declared an element and then we ref’ed that element declaration. Instead, we can inline the element declarations. On the following slide is an alternate (equivalent) way of representing the schema shown previously, using inlined element declarations.
22 Elements Declared Inline
23 Anonymous types (no name)
24 Named Types The following slide shows an alternate (equivalent) schema which uses a named type.
25 Named type Named Types
26 Please note that is equivalent to Element A references the complexType foo. Element A has the complexType definition inlined in the element declaration.
27 type Attribute or complexType Child Element, but not Both! An element declaration can have a type attribute, or a complexType child element, but it cannot have both a type attribute and a complexType child element. …
28 Summary of Declaring Elements (two ways to do it) A simple type (e.g., xsd:string) or the name of a complexType … 1 2 A nonnegative integer A nonnegative integer or "unbounded" Note: minOccurs and maxOccurs can only be used in nested (local) element declarations.
29 XML Schemas DTD:
30 Elements v.s. Types in XML Schema DTD:
31 Types: –Simple types (integers, strings,...) –Complex types (regular expressions, like in DTDs) Element-type-element alternation: –Root element has a complex type –That type is a regular expression of elements –Those elements have their complex types... –... –On the leaves we have simple types Elements v.s. Types in XML Schema
32 Local and Global Types in XML Schema Local type: [define locally the person’s type] Global type: [define here the type ttt] Global types: can be reused in other elements
33 Local v.s. Global Elements in XML Schema Local element:... Global element:... Global elements: like in DTDs
34 Regular Expressions in XML Schema Recall the element-type-element alternation: [regular expression on elements] Regular expressions: A B C = A B C A B C = A | B | C A B C = (A B C).. = (...)*.. = (...)?
35 Local Names in XML-Schema name has different meanings in person and in product
36 Subtle Use of Local Names Arbitrary deep binary tree with A elements, and a single B element
37 Attributes in XML Schema Attributes are associated to the type, not to the element Only to complex types; more trouble if we want to add attributes to simple types.
38 “Mixed” Content, “Any” Type Better than in DTDs: can still enforce the type, but now may have text between any elements Means anything is permitted there....
39 “All” Group A restricted form of & in SGML Restrictions: –Only at top level –Has only elements –Each element occurs at most once E.g. “comment” occurs 0 or 1 times
40 Derived Types by Extensions Corresponds to inheritance
41 Derived Types by Restrictions (*): may restrict cardinalities, e.g. (0,infty) to (1,1); may restrict choices; other restrictions… … [rewrite the entire content, with restrictions]... Corresponds to set inclusion
42 Simple Types String Token Byte unsignedByte Integer positiveInteger Int (larger than integer) unsignedInt Long Short... Time dateTime Duration Date ID IDREF IDREFS
43 Facets of Simple Types Examples length minLength maxLength pattern enumeration whiteSpace maxInclusive maxExclusive minInclusive minExclusive totalDigits fractionDigits Facets = additional properties restricting a simple type 15 facets defined by XML Schema
44 Facets of Simple Types Can further restrict a simple type by changing some facets Restriction = subset
45 Not so Simple Types List types: Union types Restriction types
46 Summary of XML Schema Formal Expressive Power: –Can express precisely the regular tree languages (over unranked trees) Lots of other stuff –Some form of inheritance –A “null” value –Large collection of data types
47 Summary of Schemas in SS data: –graph theoretic –data and schema are decoupled –used in data processing in XML –from grammar to object-oriented –schema wired with the data –emphasis on semantics for exchange