Presentation is loading. Please wait.

Presentation is loading. Please wait.

VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 2 Lecturer.

Similar presentations


Presentation on theme: "VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 2 Lecturer."— Presentation transcript:

1 VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 2 Lecturer : Dr. Pavle Mogin

2 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 1 Plan for XML Schema 2 Simple Types Assertion Constraint Anonymous Complex Types Deriving Complex from Simple Types Empty Types Groups XML Schema Part 0: Primer (W3C Recommendation, 2 May 2001) http://www.w3.org/TR/xmlschema-0 XML Schema Part 1: Structures http://www.w3.org/TR/xmlschema-1

3 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 2 A Classification of Simple Types XML Schema supports the following simple types: –Atomic, –List, and –Union From the XML Schema point of view, values of atomic simple types are indivisible List and union simple types are comprised of atomic simple types

4 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 3 Atomic Simple Types XML Schema supports a great number of built in atomic simple types: –string, –int, –decimal, –float, –boolean, –time, –date, –ID, –IDREF, –And many, many others

5 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 4 Creating New Atomic Simple Types New atomic simple types are defined by deriving them from existing simple types The derivation of a new type is done by restricting the range of values of an existing simple type To define the name of a new type the xsd:simpleType element is used To indicate an existing (possibly base) type the xsd:restriction element is used Facets of atomic types are used in defining new types

6 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 5 Facets XML Schema defines “facets” of the atomic types The term “facet” can be loosely interpreted as a “parameter” or even “aspect” The general facets are: –length, minLength, maxLength, –pattern (uses a regular expression language), –enumeration, –whiteSpace The facets for ordered types: –maxInclusive, maxExclusive, minInclusive, minExclusive, –totalDigits, fractionDigits

7 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 6 Defining The “Age” Simple Type <xsd:restriction base=“xsd:integer”> The xsd:minInclusive and xsd:maxExclusive are facets that are defined for the int base type (and its subclasses) in the XML Schema

8 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 7 Defining the Course TitleType There is a simple type TitleType derived in the example schema The meaning of the regular expression [A-Z]{4}\s\d{3} in the xsd:pattern facet is: –Any four capital letters followed by a white space followed by any three digits –So, SWEN 304, SWEN 432,…

9 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 8 Defining a GradeType using Enumeration

10 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 9 Assertion in XML Schema 1.1 xsd: assert is a new type of constraint introduced in the XML Schema 1.1 specification An assertion is a predicate associated with a type, which is checked for each instance of the type It allows checking the relationship of values returned by two XPath expressions The xsd:assert element is defined within a complex type The comparator belongs to { lt, gt, le, ge, eq, neq }

11 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 10 Assertion Example <xs:element name=“child" minOccurs="0" maxOccurs="unbounded“/> An instance fragment: Jack Anny Mary

12 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 11 Anonymous Type Definition An anonymous type does not have a name (and hence can not be referenced) The definition of an anonymous type directly follows the element that uses it This construct is used in the example for the assignment element and its (anonymous) complex type An anonymous type can also be a simple type: <xsd:restriction base= “xsd:nonNegativeInteger”>

13 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 12 Deriving Complex from Simple Types A fragment of the Example schema as a motivating example: <xsd:attribute name=“no” type=“xsd:int” use=“required”/> A fragment of a valid XML instance 75.50

14 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 13 Complex from Simple Types Example Suppose we want to retain no attribute, but to omit marks tags in the document: 75.50 A corresponding fragment of the XML schema: <xsd:attribute name=“no” type=“xsd:int” use =“required”/>

15 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 14 Empty Content There is more than one way to define an element with an empty content Perhaps the most straight forward one is the following <xsd:element name=“assignment” minOccurs=“0” maxOccurs=“ununbounded”> <xsd:attribute name=“marks” type=“xsd:decimal”/> <xsd:attribute name=“no” type=“xsd:int” use=“required”/> The corresponding XML document fragment

16 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 15 anyType The xsd:anyType is an abstraction called ur-type It is the base type from which all simple and complex types are derived It is also default type So it can be declared in the following two ways: or The content of an element defined this way is unconstrained, it can be anything

17 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 16 Building Content Models XML Schema has a number of constructs for building complex content models These are called groups and they are: –xsd:sequence, (used to denote the exact order of elements) –xsd:choice, (used to express “exclusive or” choice) –xsd:group, (used to define and later reference a group of elements) and –xsd:all (used to denote that the element order in an instance document is immaterial) The groups can be constrained by minOccurs and maxOccurs attributes

18 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 17 Groups of Elements XML Schema enables defining named and unnamed groups of elements Named groups can be repeatedly referenced and are defined using markup Unnamed groups are defined using markup: … A group may contain several other groups

19 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 18 A xsd:group Example The definition of a group: <xsd:element name=“HomeAddress” type=“Address”/> <xsd:element name=“PostalAddress” type=“Address”/> The use of named groups simplifies their: –Repetitive referencing, and –Updating

20 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 19 The Address Type The Address type <xsd:element name=“street” type=“xsd:string”/>

21 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 20 A Complex Content Model <xsd:element name=“singleAddress” type=“Address”/> …

22 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 21 xsd:all Group The xsd:all declaration must be the top markup of a content model (immediately after xsd:complexType markup) All elements in the group: –Must be individual ones (not groups), –May appear at most once, and –May appear in any order in an instance document <xsd:element name=“first_name” type=“xsd:string”/> <xsd:element name=“surname” type=“xsd:string”/>

23 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 22 Nil Values To represent a null value in an XML document instance, one can: –Omit a corresponding element, which is an implicit way, which does not convey the precise information of the reason of the omission, or –Use XML Schema’s nil mechanism with nillable attribute In the XML schema <xsd:element name = ”auditor” type=“NameType” nillable=“true”> Now, in the instance document we may either have an auditor, or we set the nil attribute to true Nil attribute is defined as a part of XML Schema for instances http://www.w3.org/2001/XMLSchema-instance namespace

24 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 23 Advantages of the Schema over the DTD The XML Schema is a superset of the DTD It supports: –The same syntax as it is for XML documents –A very rich set of built-in types –Data Type definition (simple and complex), –More flexibility in ordering elements, and –Database like constraints whose context can be precisely determined (using path expressions) A disadvantage: an XML schema is more complex than a corresponding DTD

25 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 2 24 Summary XML Schema: –Uses the same syntax as an XML document to define a new XML vocabulary, –Provides predefined tags for: Elements, Simple types, Complex types, Attributes, Constraints –Provides a rich set of predefined atomic (scalar) types, –Enables defining new simple and complex types, –Enables defining flexible structures


Download ppt "VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 2 Lecturer."

Similar presentations


Ads by Google