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 1 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 1 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 1 Lecturer : Dr. Pavle Mogin

2 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 1 Plan for XML Schema XML Schema offers predefined tags for: –Namespaces, Annotations, References –Elements (global and local), –Attributes (global and local), –Complex Types, –Simple Types (built-in and derived), and –Identity constraints –Reading: 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 1 2 XML Namespaces An XML Namespace is a collection of names identified by Uniform Resource Locator (URL) and is used for defining context In an XML document each set of tags with the same origin is associated with a URL (URI) which is given a short name This short name is used as a prefix to each element and attribute to indicate which tag set it belongs to It is supposed that the meaning of the tag is defined at the given URL XML namespaces disambiguate the meaning of tags even if they have the same name providing information about their context and origin

4 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 3 XML Schema XML Schema is the other XML meta language Similar to DTD XML Schema provides mechanisms for declaring: –Structure of XML documents, and –Constraints on the use of markup within a set of XML documents XML documents that obey to the declarations of a schema are called instances of that schema Unlike a particular DTD, a particular XML schema: –Is declared using the same syntax as XML documents themselves, –Declares the structure of XML documents in a more flexible way, and –Provides several mechanisms for: Deriving new data types by either extending, or restricting existing ones, Defining more versatile constraints

5 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 4 XML Schema as an XML Document XML Schema is an overloaded term –The name of a meta language –The term denoting the definition of a particular language As a particular language definition, XML Schema is an XML document that defines a number of tags By convention, all these tags have a unique prefix xsd: (or xs: ) that denotes that they belong to a particular namespace The semantics of these tags is defined at their namespace These predefined tags are used to build a new XML schema

6 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 5 Basic Entry Types of an XML Schema XML Schema has predefined tags for: –Namespaces –Annotations, –Elements (global and local), –Attributes (global and local), –Complex Types, –Simple Types (built-in and derived), –References That way, all these tags are treated as XML elements, having a name and attributes

7 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 6 ClassSchema.xsd The Class schema for a slightly different simple XML document (It is stored in the ClassSchema.xsd file)

8 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 7 Definition of the ClassType <xsd:element name=“lecturer” maxOccurs=“3” type=“NameType”/> <xsd:element name=“auditor” minOccurs=“0” type=“NameType”/> <xsd:element name=“student” minOccurs=“0” maxOccurs = “unbounded” type=“StudentType”/>

9 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 8 Definition of the Title and Name Types <xsd:element name=“first_name” type=“xsd:string”/>

10 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 9 Definition of the StudentType <xsd:element name=“assignment” minOccurs=“0” maxOccurs=“unbounded”> <xsd:element name=“marks” type=“xsd:decimal”/> <xsd:attribute name=“no” type=“xsd:int” use=“required”/>

11 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 10 An Instance of the ClassSchema.xsd (1) COMP 442 Pavle Mogin Ahmed AlDabagh 10

12 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 11 An Instance of the ClassSchema.xsd (2) Bad Student

13 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 12 Analysis of The ClassSchema.xsd The structure of the XML schema closely resembles the structure of an XML document: –Elements, types, attributes are defined either using tag pairs with a starting and a closing tag, or using empty tags –Element properties are defined as attributes –Namespaces are used extensively The Class schema consists of a schema element and a variety of subelements The most important once are: –element, –complexType, –simpleType –attribute

14 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 13 Use of Namespaces in Schema Each element in the schema has a prefix xsd: which is associated with the XML Schema namespace through the declaration <xsd:schema xmlns:xsd=“http://www.w3.org/2001/XMLSche ma”> at the start of the schema The prefix xsd: (or xs: ) is used by convention to denote the XML Schema namespace The same prefix appears on the names of built-in simple types –e.g. xsd:string, or xsd:int

15 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 14 annotation XML Schema provides three elements for annotating schemas for benefit of both human readers and applications: –The documentation element, which is intended for the human usage, –The appInfo element, which is intended to contain information for tools (like stylesheets), and –The annotation element, which (when used) contains the preceding ones These elements usually appear at the start of a schema definition, although can also appear at the beginning of an element or complex type definition In the example, the documentation element contains an xml:lang attribute

16 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 15 element Tags in XML Schema An element with xsd:element tag name is used to declare an element Elements are classified as –Global and –Local Global elements (and attributes) are created by declarations that appear as children of the schema element Local elements (and attributes) appear in the definitions of complex types

17 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 16 Attributes of Element Declarations An element tag of a particular XML schema definition can have different attributes: –name, (defines the tag name in the particular schema) –minOccurs (participation constraint), –maxOccurs (cardinality constraint), –type, –fixed, –default, –Ref We are going to consider only some of them

18 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 17 Global Elements Global elements are declared as children of the schema element In the example, there are two global elements declared: A global element may appear as a top-level (root) element in an XML document A global element can be referenced using ref attribute, but it can not contain references A global element can not contain structural constraints (but elements referencing it can)

19 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 18 The default Attribute The default attribute is used to declare a default value of an xsd:element The default value of an element is used only if the element’s tags appear without any content in an instance document E.g.

20 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 19 ref Attribute Instead of declaring a new element it is possible to use an existing one by referencing it using the ref attribute The referenced element has to be a global one In the example (inside the definition of ClassType ) <xsd:element ref=“comment” minOccurs=“0”/> The consequence is that an element called comment may appear in an instance of the ClassType

21 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 20 The attribute Tag An element with xsd:attribute tag name is used to declare an attribute An xsd:attribute tag can have several attributes: –name, –use, –default, –fixed, and –type

22 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 21 The use and default Attributes An xsd:attribute may be instantiated at most once in a document instance The use attribute is used to declare whether appearance of an xsd:attribute is: –required, –optional (default), or –prohibited If an xsd:attribute is defaulted, the Schema processor will insert the default value if the attribute does not appear in an instance document A defaulted attribute has to be declared as optional

23 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 22 Element Types The XML Schema supports two basic element types: –Complex, and –Simple Complex types allow elements and attributes in their contents Simple types can not have elements or attributes in their contents A simple type can be either: –Built in, or –Derived

24 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 23 Complex Types New complex types are defined using complexType element tag This definition contains a set of: –Element declarations, –Element references, and –Attribute declarations In the example, there are four complex types defined: –ClassType, –StudentType, –NameType, and –(implicitly) AssignmentType

25 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 24 Structuring Tags The sequence tag bears information about the order of element appearance (in a complex type) minOccurs and maxOccurs attributes define the structural constraint of an element The value of minOccurs attribute can be any non negative integer The value of maxOccurs attribute can be any positive integer The inequality minOccurs < maxOccurs must be satisfied Default values for both minOccurs and maxOccurs attributes is 1

26 SWEN 432 Advanced Database Design and Implementation 2015 XML Schema 1 25 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 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 1 Lecturer."

Similar presentations


Ads by Google