xml and databases exercise session 3 (courtesy of ghislain fourny/eth)

42
XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Upload: kathryn-plair

Post on 31-Mar-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

XML and DatabasesExercise Session 3

(courtesy of Ghislain Fourny/ETH)

Page 2: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Good to know: XML Schema types

Simple type - predefined or user-defined - element or attribute type

Complex type - user-defined - element type only

Empty content Simple content Complex content Mixed content

2

Page 3: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Good to know: XML Schema types

Types (can) have QNames: All predefined types

User-defined types (here simple)

3

Tags, attributes... XML Schema looks like XML... that's because it is XML!

Tags, attributes... XML Schema looks like XML... that's because it is XML!

Page 4: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Good to know: XML Schema types

They can also be anonymous.

4

Anonymous types can be defined under any xs:element or xs:attribute. Non-anonymous types have a global scope and must be defined directly under xs:schema.

Anonymous types can be defined under any xs:element or xs:attribute. Non-anonymous types have a global scope and must be defined directly under xs:schema.

Page 5: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Complex types in XML Schema

Complex type, complex content

5

Page 6: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Complex types in XML Schema

Simple content (here anonymous)

6

Page 7: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Complex types in XML Schema

Empty content Simple content restricted to "" Or a complex content without any children

Mixed content As in complex content, with an additional attribute

mixed set to true in xs:complexType

7

Page 8: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercises 1-3

Passenger

Flight

Airport

Booking

8

Page 9: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercises 1-3

Passenger: name, address, passport number

Flight: ID, number of seats, date, origin, dest

Airport: name, code, tax value

Booking: credit card, flight, passenger

9

Page 10: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 1: XML Data

Sample data

10

Page 11: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 1: XML Data

How to prevent this?

11

Page 12: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 1: XML Data

How to prevent this?

With a DTD/Schema!

12

Page 13: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: XML Schema Modelling

13

Page 14: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: XML Schema Modelling

14

Passport number name address

Passenger

Page 15: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: XML Schema Modelling

15

code name tax

Passport number name address

Airport

Passenger

Page 16: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: XML Schema Modelling

16

code name tax flightID seatNo date

Passport number name address

Airport Flight

Passenger

Page 17: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: XML Schema Modelling

17

code name tax flightID seatNo date

Passport number name address

Airport Flight

Passenger

source

dest

Page 18: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: XML Schema Modelling

18

code name tax flightID seatNo date

credit card

Passport number name address

Airport Flight

Passenger

source

dest

book

Page 19: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: XML Schema Modelling

19

code name tax flightID seatNo date

credit card

Passport number name address

Airport Flight

Passenger

source

dest

book

1

1

N

N

N

M

Page 20: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: What‘s wrong?

20

Page 21: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: Inconsistency

21

Page 22: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: Inconsistency

22

Page 23: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: Redundancy

23

Page 24: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: Redundancy

24

Page 25: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: Extraneous data

25

Page 26: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: A Schema for Passenger

26

Passport number name address

Passenger

Page 27: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: A Schema for Passenger

27

Passport number name address

Passenger

Page 28: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: A Schema for Flight

28

flightID seatNo date

Airport Flight

source

dest

Page 29: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: A Schema for Flight

29

flightID seatNo date

Airport Flight

source

dest

Page 30: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: A Schema for Flight

30

flightID seatNo date

Airport Flight

source

dest

Page 31: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: A Schema for Flight

31

flightID seatNo date

Airport Flight

source

dest

Page 32: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: A Schema for Airport

32

code name tax

Airport

Page 33: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: A Schema for Airport

33

code name tax

Airport

Page 34: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: A Schema for Airport

34

code name tax

Airport

Page 35: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 2: Root Element

35

Page 36: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 3: DTD and XML Schema

36

Page 37: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 3: Corresponding XML Schema

37

Page 38: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 4: Corresponding XML Schema

38

Page 39: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 3: Corresponding XML Schema

39

Page 40: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 3: Corresponding XML Schema

40

Page 41: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science

Exercise 3: Corresponding XML Schema

41

Page 42: XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)

Department of Computer Science 42

Hope to see you next week!Hope to see you next week!