XML and Databases Exercise Session 3 courtesy of

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

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 § Department of Computer Science 2

Good to know: XML Schema types § Types (can) have QNames: § § All predefined types User-defined types (here simple) Department of Computer Science Tags, attributes. . . XML Schema looks like XML. . . that's because it is XML! 3

Good to know: XML Schema types § They can also be anonymous. Anonymous types can be defined under any xs: element or xs: attribute. Nonanonymous types have a global scope and must be defined directly under xs: schema. Department of Computer Science 4

Complex types in XML Schema § Complex type, complex content Department of Computer Science 5

Complex types in XML Schema § Simple content (here anonymous) Department of Computer Science 6

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: complex. Type Department of Computer Science 7

Exercises 1 -3 § Passenger § Flight § Airport § Booking Department of Computer Science 8

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 Department of Computer Science 9

Exercise 1: XML Data § Sample data Department of Computer Science 10

Exercise 1: XML Data § How to prevent this? Department of Computer Science 11

Exercise 1: XML Data § How to prevent this? § With a DTD/Schema! Department of Computer Science 12

Exercise 2: XML Schema Modelling Department of Computer Science 13

Exercise 2: XML Schema Modelling Passenger Passport number name Department of Computer Science address 14

Exercise 2: XML Schema Modelling code name tax Airport Passenger Passport number name Department of Computer Science address 15

Exercise 2: XML Schema Modelling code name tax flight. ID seat. No date Flight Airport Passenger Passport number name Department of Computer Science address 16

Exercise 2: XML Schema Modelling code name flight. ID tax seat. No date source Flight Airport dest Passenger Passport number name Department of Computer Science address 17

Exercise 2: XML Schema Modelling code name flight. ID tax seat. No date source Flight Airport dest book credit card Passenger Passport number name Department of Computer Science address 18

Exercise 2: XML Schema Modelling code name flight. ID tax 1 source seat. No date N Flight Airport 1 dest N M book credit card N Passenger Passport number name Department of Computer Science address 19

Exercise 2: What‘s wrong? Department of Computer Science 20

Exercise 2: Inconsistency Department of Computer Science 21

Exercise 2: Inconsistency Department of Computer Science 22

Exercise 2: Redundancy Department of Computer Science 23

Exercise 2: Redundancy Department of Computer Science 24

Exercise 2: Extraneous data Department of Computer Science 25

Exercise 2: A Schema for Passenger Passport number name Department of Computer Science address 26

Exercise 2: A Schema for Passenger Passport number name Department of Computer Science address 27

Exercise 2: A Schema for Flight flight. ID seat. No date source Flight Airport dest Department of Computer Science 28

Exercise 2: A Schema for Flight flight. ID seat. No date source Flight Airport dest Department of Computer Science 29

Exercise 2: A Schema for Flight flight. ID seat. No date source Flight Airport dest Department of Computer Science 30

Exercise 2: A Schema for Flight flight. ID seat. No date source Flight Airport dest Department of Computer Science 31

Exercise 2: A Schema for Airport code name tax Airport Department of Computer Science 32

Exercise 2: A Schema for Airport code name tax Airport Department of Computer Science 33

Exercise 2: A Schema for Airport code name tax Airport Department of Computer Science 34

Exercise 2: Root Element Department of Computer Science 35

Exercise 3: DTD and XML Schema Department of Computer Science 36

Exercise 3: Corresponding XML Schema Department of Computer Science 37

Exercise 4: Corresponding XML Schema Department of Computer Science 38

Exercise 3: Corresponding XML Schema Department of Computer Science 39

Exercise 3: Corresponding XML Schema Department of Computer Science 40

Exercise 3: Corresponding XML Schema Department of Computer Science 41

Hope to see you next week! Department of Computer Science 42
- Slides: 42