Top Banner
Dr. Alexandra I. Cristea http://www.dcs.warwick.ac.uk/ ~acristea/ CS 253: Topics in Database Systems: C1
54

Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

Mar 28, 2015

Download

Documents

Jada Murray
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

Dr. Alexandra I. Cristea

http://www.dcs.warwick.ac.uk/~acristea/

CS 253: Topics in Database Systems: C1

Page 2: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

2

Lecturers

• Alexandra I. Cristea

• Hugh Darwen: [email protected]

Page 3: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

3

Schedule• Usual:

– Tue 13-14, CS104– Thu 13-14, CS104– Fri 13-14, CS104

• Exceptions:– Others: TBA: check forum, website, course

Page 4: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

4

Slides

• Thanks to:– W3C courses– Others: mentioned directly

Page 5: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

5

Contact

• Forum:

http://forums.warwick.ac.uk/wf/browse/forum.jsp?fid=2194 • IF (and ONLY IF) a question is personal, you

might address it to AIC, HD – FORMAT: subject of email should contain ‘CS253’

and topic of the email (otherwise it will be filtered out)

Page 6: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

6

Course site(s):

• Current:– http://www.dcs.warwick.ac.uk/~acristea/courses/CS

253/

– Will contain current slides, as taught at the course– Will contain notifications: check BEFORE & AFTER

the course

• Official:– http://www.dcs.warwick.ac.uk/undergraduate/modules/cs253

.html

Page 7: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

7

Content: Topics1. XML

2. XML Query languages

3. Temporal Data – Hugh Darwen

4. SQL: Missing Info without Nulls – Hugh Darwen

5. SQL: Concurrency

6. SQL: The “Askew Wall” – Hugh Darwen

7. Q&A, Exam preparation

Page 8: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

8

Books & Material• Online material from W3C and W3C schools a.o. (as

mentioned in the slides and notes check also the notes in the powerpoints)

• H. Darwen, An Introduction to Relational Database Theory, ISBN 978-87-7681-500-4 Bookboon

• Korth and Silberschatz, Database System Concepts, McGraw-Hill,1991.

• Ullman J D, Principles of Database Systems (Vols 1 and 2), Computer Science Press,1988.

Page 9: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

9

Purpose of this course

• A selection of topics related to databases

• A more modern view on current database implementation & research

Page 10: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

10

Overlaps and sequencing

• Form: optional

• Prerequisites – CS252: Fundamentals of Database Systems

Page 11: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

11

Organization of the course• 7.5 CATS• CS, CSE, CBS, Mathematics• ~ 15 1-hour lectures• Exam at the end: 2 hours• Rules of the game:

– Read also comments on the slides and additional reading material.

– Presence is optional, but beware: slides-only are NOT ENOUGH to learn from for the exam; you need to participate, take your own notes, so self-study!

Page 12: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

12

Scope of CS 253

• A selection of topics on current database systems,• As well as a selection of topics not covered in the

fundamental course part

• What this course is not:– This course is not an exhaustive course on database

topics– This course has no seminars or practical part, so it is

based on lectures and self-study only

Page 13: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

13

XML

Page 14: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

14

XML history

• Inception: circa 1996

• The Extensible Markup Language (XML) became a W3C Recommendation 10. February 1998.

Page 15: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

15

What is XML?• XML stands for EXtensible Markup

Language • XML was designed to describe data • XML is more of a standard and

supporting structure than a standalone programming language

• XML is a markup language much like HTML – wrong!: meta-language

Page 16: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

16

How does XML work?

• XML tags are not predefined. You must define your own tags

• XML uses a Document Type Definition (DTD) or an XML Schema to describe the data

• XML with a DTD or XML Schema is designed to be self-descriptive

Page 17: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

17

XML is Free and Extensible• XML tags are not predefined. You must

"invent" your own tags.• The tags used to mark up HTML documents

and the structure of HTML documents are predefined. The author of HTML documents can only use tags that are defined in the HTML standard (like <p>, <h1>, etc.).

• XHTML is XML but not vice-versa.

Page 18: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

18

XML does not DO anything• XML was created to structure, store and to send

information

<note> <to>John</to> <from>Jane</from>

<heading>Reminder</heading> <body>Don't forget the book!</body>

</note>

Page 19: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

19

Main Difference XML, HTML• XML was designed to carry data.• XML is not a replacement for HTML.

XML and HTML were designed with different goals:– XML was designed to describe data and to focus on what

data is.

– HTML was designed to display data and to focus on how data looks.

• HTML is about displaying information, while XML is about describing information.

• Syntax: XML is well formed, just like XHTML

Page 20: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

20

XML is a Complement to HTML

• XML is not a replacement for HTML.– In future Web development it is most likely

that XML will be used to describe the data, while HTML will be used to format and display the same data.

• XML is a cross-platform, software and hardware independent tool for transmitting information.

Page 21: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

21

Benefits XML• extensibility and structured nature of XML

allows it to be used for communication between different systems

• from one source of XML-based information you can format and distribute it via a multitude of different channels – XSL files act as templates, allowing a single

stylesheet to be used to format multiple pages or the same content for multiple distribution channels

Page 22: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

22

XML in Future Web Development

• XML is starting to be everywhere.

• the XML standard has been developed quickly and a large number of software vendors have adopted it.

• XML might be the most common tool for all data manipulation and data transmission.

Page 23: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

23

XML Can be Used to Create New Languages• XML is the mother of WAP and WML.

– WAP: standard for web browser for mobile devices

– The Wireless Markup Language (WML), used to markup Internet applications for handheld devices like mobile phones, is written in XML.

• And many others …

Page 24: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

24

• Question: When should I use XML?

• Answer: When you need a buzzword in your resume.

Page 25: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

25

Viewing XML• to view XML documents hierarchically or view

their output, you need an XML parser and processor.

• there are a number of these tools available:• See examples at: • http://www.stylusstudio.com/xml_download.html • http://www.w3schools.com/xml/xml_parser.asp • Please note, however: XML was not designed to

display data.

Page 26: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

26

The basic XML flow

Page 27: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

27

XML Rules1. Every start-tag must have a matching end-tag.

2. Tags cannot overlap. Proper nesting is required.

3. XML documents can only have one root element.

4. Element names must obey the following XML naming conventions: a) Names must start with letters or the "_" character.

Names cannot start with numbers of punctuation characters.

b) After the first character, numbers and punctuation characters are allowed.

Page 28: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

28

XML Rules (cont.)

c) Names cannot contain spaces. d) Names should not contain the ":" character as it is a

"reserved" character. e) Names cannot start with the letters "xml" in any

combination of case. f) The element name must come directly after the "<" without

any spaces between them.

5. XML is case sensitive. 6. XML preserves white space within text. 7. Elements may contain attributes. If an attribute is

present, it must have a value, even if it is an empty string "".

Page 29: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

29

Spot the error!

<?xml version="1.0" encoding="ISO-8859-1"?>

<note date=12/11/2002>

<to>Tove</to>

<from>Jani</from>

</note>

Page 30: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

30

Spot the error!

<?xml version="1.0" encoding="ISO-8859-1"?>

<note date="12/11/2002">

<to>Tove</to>

<from>Jani</from>

</note>

Page 31: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

31

With XML, CR / LF is converted to LF

• Windows: CR + LF

• Unix: LF

• Macintosh: CR

Page 32: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

32

There is Nothing Special About XML

• plain text w XML tags

• Software that can handle plain text can also handle XML.

• In an XML-aware application, the XML tags can be handled specially: – Visibility,– Functional meaning, etc.

Page 33: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

33

Is this an error?

<note>

<to>Tove</to>

<from>Jani</from>

<body>Don't forget me this weekend!</body>

</note>

<heading>Reminder</heading>

Page 34: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

34

XML Elements have Relationships

• Elements are related as parents and children.

• Root element / Parents

• Children / Siblings

Page 35: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

35

Elements• An element consists of all the information from the

beginning of a start-tag to the end of an end-tag including everything in between.

• E.g. from (X)HTML, all of the following would be the equivalent of one element, named h1:

<h1>This is a heading.</h1> – Where, <h1> is the start tag, </h1> is the end tag, and the

content is in between.

• Each XML document has a root element within which all other elements are nested.

Page 36: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

36

Examples

• See at:– http://www.intranetjournal.com/articles/200

402/ij_02_10_04a.html– http://prolearn.dcs.warwick.ac.uk/caf/gipfB

egIntAdv.xml– Search more by yourself and familiarize

yourself with the syntax!

Page 37: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

37

XML Attributes

• XML elements can have attributes.

• From HTML you will remember this: <IMG SRC="computer.gif">

• The SRC attribute provides additional information about the IMG element.

Page 38: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

38

Attributes versus Elements

• <person sex="female"> <firstname>Anna</firstname> <lastname>Smith</lastname> </person>

• <person> <sex>female</sex> <firstname>Anna</firstname> <lastname>Smith</lastname> </person>

Page 39: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

39

Comments

• same as in any other languages with line(s) of code whose sole purpose is to provide the developer, and anyone reading the code in the future, information about the code.

<!-- all the comments go in here -->

Page 40: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

40

XML Validation: Well Formed-ness

• An XML document is well formed, if all the XML rules are obeyed.

(with 7 XML rules as defined in slides 27-28)

Page 41: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

41

XML declaration

• Every XML document begins with a declaration (not mandatory, good practice)

<?xml version=“1.0”?> • Or, using optional attributes:<?xml version=“1.0” encoding=“UTF-16” standalone=“yes”?>

Page 42: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

42

Document Type Definition (DTD)

• which tags and attributes are allowed,

• where they can be placed, and

• whether or not they can be nested within a given document.

Page 43: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

43

Document Type Declaration (DOCTYPE)

• <!DOCTYPE MovieCatalog SYSTEM "movie_catalog.dtd">

Root document element

URL to DTD(external subset via a system identifier)

Page 44: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

44

Internal vs External DTD declaration

Internal:

<!DOCTYPE foo [ <!ENTITY greeting "hello"> ]>

External, public:

<!DOCTYPE html PUBLIC "//W3C//DTD HTML 4.01//EN” >

Page 45: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

45

Valid XML Documents

• A "Valid" XML document is a "Well Formed" XML document, which also conforms to the rules of a Document Type Definition (DTD):

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE note SYSTEM "InternalNote.dtd">

<note> <to>Tom</to> <from>Jane</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body>

</note>

Page 46: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

46

Validator

• http://xmlvalidator.new-studio.org/

• Also at: http://validator.w3.org/#validate_by_input

Page 47: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

47

Internal DTD<?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> <!ATTLIST body lang CDATA "EN"> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>

Page 48: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

48

External DTD

<!ELEMENT note (to,from,heading,body)>

<!ELEMENT to (#PCDATA)>

<!ELEMENT from (#PCDATA)>

<!ELEMENT heading (#PCDATA)>

<!ELEMENT body (#PCDATA)>

>> saved as file note.dtd

Page 49: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

49

XML Schema (XSD)

• XML Schema is an XML based alternative to DTD.

• W3C supports an alternative to DTD called XML Schema:http://www.w3.org/XML/Schema

Page 50: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

50

Displaying your XML Files with CSS?• It is possible to use CSS to format an XML document.• Example:• XML file: The CD catalog• style sheet: The CSS file• product: The CD catalog formatted with the CSS file• Below is a fraction of the XML file. The second line,

<?xml-stylesheet type="text/css" href="cd_catalog.css"?>, links the XML file to the CSS file

Page 51: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

51

Displaying XML with XSL

• XSL is the preferred style sheet language of XML.

• XSL (the eXtensible Stylesheet Language) is far more sophisticated than CSS.

• examples:– View the XML file, the XSL style sheet, and

View the result.

<?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href=“simple.xsl"?>

Page 52: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

52

XML Conclusions• We have learned:

– XML history– What it is– How it works– Differences to (X)HTML– XML flow– XML Rules– XML Elements, Relationships, Attributes,

Comments– Well-formed-ness concept– XML supporting frame: XML Schema or DTD– Generics on displaying XML

Page 53: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

53

Why an XML Editor?• XML Schema to define XML structures and data

types • XSLT to transform XML data • SOAP to exchange XML data between applications • WSDL to describe web services • RDF to describe web resources • XPath and XQuery to access XML data • SMIL to define graphics • Altova's XMLSpy

– 30 days free trial– http://www.altova.com/products/xmlspy/xsl_xslt_editor.html

Page 54: Dr. Alexandra I. Cristea acristea/ CS 253: Topics in Database Systems: C1.

54

• Next:– We look at how to access elements and

attributes inside the XML– This can be done via …

– XPATH