pal gov.tutorial2.session3.xml schemas

33
1 PalGov © 2011 1 PalGov © 2011 فلسطينيةلكترونية الية الحكومة ا أكاديمThe Palestinian eGovernment Academy www.egovacademy.ps Dr. Ismail M. Romi Palestine Polytechnic University Tutorial II: Data Integration and Open Information Systems Session3 XML Schemas

Upload: mustafa-jarrar

Post on 26-May-2015

329 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Pal gov.tutorial2.session3.xml schemas

1PalGov © 2011 1PalGov © 2011

أكاديمية الحكومة اإللكترونية الفلسطينيةThe Palestinian eGovernment Academy

www.egovacademy.ps

Dr. Ismail M. Romi

Palestine Polytechnic University

Tutorial II: Data Integration and Open Information Systems

Session3

XML Schemas

Page 2: Pal gov.tutorial2.session3.xml schemas

2PalGov © 2011 2PalGov © 2011

About

This tutorial is part of the PalGov project, funded by the TEMPUS IV program of the

Commission of the European Communities, grant agreement 511159-TEMPUS-1-

2010-1-PS-TEMPUS-JPHES. The project website: www.egovacademy.ps

University of Trento, Italy

University of Namur, Belgium

Vrije Universiteit Brussel, Belgium

TrueTrust, UK

Birzeit University, Palestine

(Coordinator )

Palestine Polytechnic University, Palestine

Palestine Technical University, PalestineUniversité de Savoie, France

Ministry of Local Government, Palestine

Ministry of Telecom and IT, Palestine

Ministry of Interior, Palestine

Project Consortium:

Coordinator:

Dr. Mustafa Jarrar

Birzeit University, P.O.Box 14- Birzeit, Palestine

Telfax:+972 2 2982935 [email protected]

Page 3: Pal gov.tutorial2.session3.xml schemas

3PalGov © 2011 3PalGov © 2011

© Copyright Notes

Everyone is encouraged to use this material, or part of it, but should

properly cite the project (logo and website), and the author of that part.

No part of this tutorial may be reproduced or modified in any form or by

any means, without prior written permission from the project, who have

the full copyrights on the material.

Attribution-NonCommercial-ShareAlike

CC-BY-NC-SA

This license lets others remix, tweak, and build upon your work non-

commercially, as long as they credit you and license their new creations

under the identical terms.

Page 4: Pal gov.tutorial2.session3.xml schemas

4PalGov © 2011

Tutorial Map

Topic h

Session 1: XML Basics and Namespaces 3

Session 2: XML DTD’s 3

Session 3: XML Schemas 3

Session 4: Lab-XML Schemas 3

Session 5: RDF and RDFs 3

Session 6: Lab-RDF and RDFs 3

Session 7: OWL (Ontology Web Language) 3

Session 8: Lab-OWL 3

Session 9: Lab-RDF Stores -Challenges and Solutions 3

Session 10: Lab-SPARQL 3

Session 11: Lab-Oracle Semantic Technology 3

Session 12_1: The problem of Data Integration 1.5

Session 12_2: Architectural Solutions for the Integration Issues 1.5

Session 13_1: Data Schema Integration 1

Session 13_2: GAV and LAV Integration 1

Session 13_3: Data Integration and Fusion using RDF 1

Session 14: Lab-Data Integration and Fusion using RDF 3

Session 15_1: Data Web and Linked Data 1.5

Session 15_2: RDFa 1.5

Session 16: Lab-RDFa 3

Intended Learning Objectives

A: Knowledge and Understanding

2a1: Describe tree and graph data models.

2a2: Understand the notation of XML, RDF, RDFS, and OWL.

2a3: Demonstrate knowledge about querying techniques for data

models as SPARQL and XPath.

2a4: Explain the concepts of identity management and Linked data.

2a5: Demonstrate knowledge about Integration &fusion of

heterogeneous data.

B: Intellectual Skills

2b1: Represent data using tree and graph data models (XML &

RDF).

2b2: Describe data semantics using RDFS and OWL.

2b3: Manage and query data represented in RDF, XML, OWL.

2b4: Integrate and fuse heterogeneous data.

C: Professional and Practical Skills

2c1: Using Oracle Semantic Technology and/or Virtuoso to store

and query RDF stores.

D: General and Transferable Skills2d1: Working with team.

2d2: Presenting and defending ideas.

2d3: Use of creativity and innovation in problem solving.

2d4: Develop communication skills and logical reasoning abilities.

Page 5: Pal gov.tutorial2.session3.xml schemas

5PalGov © 2011 5PalGov © 2011

Session ILO’s:

After completing this session students will be able to:

•Manage data represented in XML.

•Represent data using tree and graph data models.

•Build Well-Formed XML Document.

Page 6: Pal gov.tutorial2.session3.xml schemas

6PalGov © 2011 6PalGov © 2011

Session4: XML Schemas

Session Overview:

<Benefits of XML Schemas />

<How to create and use XML Schemas/>

<How to document your XML Schemas/>

Page 7: Pal gov.tutorial2.session3.xml schemas

7PalGov © 2011 7PalGov © 2011

XML Schema

• The term XML Schema is used to refer to the specific

W3C XML Schema technology.

• W3C XML Schemas, much like DTDs, enable you to

describe the structure of an XML document.

• XML Schema definitions are also commonly referred

to as XSDs.

Page 8: Pal gov.tutorial2.session3.xml schemas

8PalGov © 2011 8PalGov © 2011

Benefits of XML Schemas

XML Schemas are created using basic XML, while DTDs

utilize a separate syntax.

XML Schemas fully support the Namespace

Recommendation.

XML Schemas enable you to validate text element content

based on built-in and user-defined data types.

XML Schemas enable you to more easily create complex

and reusable content models.

XML Schemas enable the modeling of programming

concepts such as object inheritance and type substitution.

Page 9: Pal gov.tutorial2.session3.xml schemas

9PalGov © 2011 9PalGov © 2011

Do We Still Need DTDs?

• XML Schemas provide better features for describing

documents—as well as a more common syntax—they

provide no ENTITY functionality.

• In many XML documents and applications, the ENTITY

declaration is important.

• DTD can be embedded in the xml document.

• DTD supported by the SGML.

Page 10: Pal gov.tutorial2.session3.xml schemas

10PalGov © 2011 10PalGov © 2011

XML Schemas

XML Schema divided into three parts:

An introduction to XML Schema concepts at:

www.w3.org/TR/xmlschema-0/

A document that defines all of the structures used in XML

Schemas at: ww.w3.org/TR/xmlschema-1/

A document that describes XML Schema data types at

www.w3.org/TR/xmlschema-2/

Page 11: Pal gov.tutorial2.session3.xml schemas

11PalGov © 2011 11PalGov © 2011

The XML Schema Document

• Most XML Schemas are stored within a separate XML

document.

• XML Schemas function very similarly to external DTDs

• XML document contains a reference to the XML Schema

that defines its vocabulary.

• An XML document that adheres to a particular XML

Schema vocabulary is called an XML Schema instance document.

Page 12: Pal gov.tutorial2.session3.xml schemas

12PalGov © 2011 12PalGov © 2011

XSD Example

<?xml version=‖1.0‖?>

<schema xmlns=‖http://www.w3.org/2001/XMLSchema‖

xmlns:target=‖http://www.example.com/name‖

targetNamespace=‖http://www.example.com/name‖

elementFormDefault=‖qualified‖>

<element name=‖name‖>

<complexType>

<sequence>

<element name=‖first‖ type=‖string‖/>

<element name=‖middle‖ type=‖string‖/>

<element name=‖last‖ type=‖string‖/>

</sequence>

<attribute name=‖title‖ type=‖string‖/>

</complexType>

</element>

</schema>

Page 13: Pal gov.tutorial2.session3.xml schemas

13PalGov © 2011 13PalGov © 2011

The <schema> Element

The <schema> element is the root element of every XML

Schema:

<?xml version="1.0"?>

<xs:schema>

...

...

</xs:schema>

Page 14: Pal gov.tutorial2.session3.xml schemas

14PalGov © 2011 14PalGov © 2011

The <schema> Element….Cont

The <schema> element may contain some attributes.

A schema declaration often looks something like this:

<?xml version="1.0"?>

<xs:schema

xmlns:xs= “http://www.w3.org/2001/XMLSchema”

targetNamespace= “http://www.w3schools.com”

xmlns= “http://www.w3schools.com”

elementFormDefault= "qualified">

...

...

</xs:schema>

Page 15: Pal gov.tutorial2.session3.xml schemas

15PalGov © 2011 15PalGov © 2011

The XML schema Namespace

• You can use any of the following <schema>:<schema

xmlns=”http://www.w3.org/2001/XMLSchema”>

<xs:schema

xmlns:xs=”http://www.w3.org/2001/XMLSchema”>

<xsd:schema

xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>

Page 16: Pal gov.tutorial2.session3.xml schemas

16PalGov © 2011 16PalGov © 2011

• Indicates that the elements and data types

used in the schema come from the

―http://www.w3.org/2001/XMLSchema" namespace.

• It also specifies that the elements and data

types that come from the

―http://www.w3.org/2001/XMLSchema" namespace

should be prefixed with xs: or xsd:

Page 17: Pal gov.tutorial2.session3.xml schemas

17PalGov © 2011 17PalGov © 2011

Target Namespaces

• The primary purpose of XML Schemas is to declare

vocabularies.

• These vocabularies can be identified by a namespace that

is specified in the target namespace attribute.

• When declaring a target namespace, it is important to

include a matching namespace declaration.

<xs:schema xmlns:xs=‖http://www.w3.org/2001/XMLSchema‖

targetNamespace=‖http://www.example.com/name‖

xmlns=‖http://www.example.com/name‖>

Indicates that the

elements defined by this

schema come from this

target namespace.

Indicates the

default namespace.

Page 18: Pal gov.tutorial2.session3.xml schemas

18PalGov © 2011 18PalGov © 2011

Element and Attribute Qualification

<schema xmlns=‖http://www.w3.org/2001/XMLSchema‖

xmlns:target=‖http://www.example.com/name‖

targetNamespace=‖http://www.example.com/name‖

elementFormDefault=‖qualified‖>

elementFromDefault = ―qualified‖ or ―unqualified‖

attributeFromDefault ― qualified‖ or ―unqualified‖

• qualified: if it has an associated namespace.

• unqualified: if it hasn’t associated namespaces

Page 19: Pal gov.tutorial2.session3.xml schemas

19PalGov © 2011 19PalGov © 2011

Simple <element> Declarations

<xs:element name="xxx" type="yyy"/>

xxx: the name of the element • The name must follow the rules for XML names.

yyy: the data type of the element.

XML Schema has a lot of built-in data types.

The most common types are:– xs:string

– xs:decimal

– xs:integer

– xs:boolean

– xs:date

– xs:time

Page 20: Pal gov.tutorial2.session3.xml schemas

20PalGov © 2011 20PalGov © 2011

Example

• Here are some simple XML elements:

<lastname>Jones</lastname>

<age>36</age>

<dateborn>1970-03-27</dateborn>

• Here are the corresponding simple element

definitions:

<xs:element name="lastname" type="xs:string"/>

<xs:element name="age" type="xs:integer"/>

<xs:element name="dateborn" type="xs:date"/>

Page 21: Pal gov.tutorial2.session3.xml schemas

21PalGov © 2011 21PalGov © 2011

Cardinality

• Cardinality represents the number of

occurrences of a specific element within a

content model.

<element name=‖first‖ type=‖string‖ minOccurs=‖x‖ maxOccurs=‖y‖/>

• x : minimum number of occurrence, default =1

• y : maximum number of occurrence, unbound: open occurrence

Page 22: Pal gov.tutorial2.session3.xml schemas

22PalGov © 2011 22PalGov © 2011

Default and Fixed Values

Simple elements may have a default value OR a fixed value specified.

Default value is automatically assigned to the element when no other value is specified.

In the following example the default value is "red":

<xs:element name="color" type="xs:string" default="red"/>

Fixed value is also automatically assigned to the element, and you cannot specify another value. In the following example the fixed value is "red":

<xs:element name="color" type="xs:string" fixed="red"/>

Page 23: Pal gov.tutorial2.session3.xml schemas

23PalGov © 2011 23PalGov © 2011

<complexType> Declarations

A complex element is an XML element that contains other elements and/or attributes.

There are four kinds of complex elements:

empty elements

elements that contain only other elements

elements that contain only text

elements that contain both other elements and text

Note: Each of these elements may contain attributes as well!

Page 24: Pal gov.tutorial2.session3.xml schemas

24PalGov © 2011 24PalGov © 2011

empty elements

• A complex XML element, "product", which is

empty:

<product pid="1345"/>

Page 25: Pal gov.tutorial2.session3.xml schemas

25PalGov © 2011 25PalGov © 2011

elements that contain only other elements

• A complex XML element, "employee", which

contains only other elements:

<employee>

<firstname>John</firstname>

<lastname>Smith</lastname>

</employee>

Page 26: Pal gov.tutorial2.session3.xml schemas

26PalGov © 2011 26PalGov © 2011

elements that contain only text

• A complex XML element, "food", which

contains only text:

<food type="dessert“ Ice cream</food>

Page 27: Pal gov.tutorial2.session3.xml schemas

27PalGov © 2011 27PalGov © 2011

elements that contain both other elements and text

• A complex XML element, "description",

which contains both elements and text:

<description> It happened on

<date lang="norwegian">03.03.99</date> ....

</description>

Page 28: Pal gov.tutorial2.session3.xml schemas

28PalGov © 2011 28PalGov © 2011

How to Define a Complex Element

• Look at this complex XML element,

"employee", which contains only other

elements:

<employee>

<firstname>John</firstname>

<lastname>Smith</lastname>

</employee>

Page 29: Pal gov.tutorial2.session3.xml schemas

29PalGov © 2011 29PalGov © 2011

The "employee" element can be declared directly by naming the element, like this:

<xs:element name="employee">

<xs:complexType>

<xs:sequence>

<xs:element name="firstname" type="xs:string"/>

<xs:element name="lastname“ type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

• If you use the method described above, only the "employee" element can use the specified complex type.

• Note that the child elements, "firstname" and "lastname", are surrounded by the <sequence> indicator. This means that the child elements must appear in the same order as they are declared.

Page 30: Pal gov.tutorial2.session3.xml schemas

30PalGov © 2011 30PalGov © 2011

<attribute> Declarations

• The syntax for defining an attribute is:

<xs:attribute name="xxx" type="yyy"/>

– Where xxx is the name of the attribute and yyy specifies

the data type of the attribute.

– Simple elements can’t have attributes

Page 31: Pal gov.tutorial2.session3.xml schemas

31PalGov © 2011 31PalGov © 2011

Summary

• XML Schema is used to refer to the specific W3C

XML Schema technology.

• W3C XML Schemas, much like DTDs, enable you

to describe the structure of an XML document.

Page 32: Pal gov.tutorial2.session3.xml schemas

32PalGov © 2011 32PalGov © 2011

Refrences

• Hunter, H, Rafter, J., Fawcett, J., Vlist, E., Ayers, D., Duckett, J., Watt,

A., McKinnon,L., (2007), "Beginning XML", 4th Ed.,Wiley Publishing Inc: Indiana, USA.

• Ray, E., (2003), "Learning XML", 2nd Ed., O’Rreilly Media Inc.: USA.

• Amiano, M., D'Cruz, C., Ethier, K., Thomas, M., (2006), XML:

Problem - Design – Solution", Wiley Publishing Inc: Indiana, USA.

• http://www.w3.org

• http://www.w3schools.com

• http://www.xml.com

• http://www.xml.org

Page 33: Pal gov.tutorial2.session3.xml schemas

33PalGov © 2011 33PalGov © 2011

<e-Gov> Thank you </e-Gov>