©Silberschatz, Korth and Sudarshan8.1Database System Concepts Chapter 8: Object-Oriented Databases Need for Complex Data Types The Object-Oriented Data.

Slides:



Advertisements
Similar presentations
XML Examples. Bank Information Basic structure: A-101 Downtown 500 … Johnson Alma Surrey … A-101 Johnson …
Advertisements

©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
Chapter 10: XML. ©Silberschatz, Korth and Sudarshan10.2Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium.
©Silberschatz, Korth and Sudarshan8.1Database System Concepts Chapter 8: Object-Oriented Databases Need for Complex Data Types The Object-Oriented Data.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 10: XML.
Chapter 9: Object-Relational Databases
1 COS 425: Database and Information Management Systems XML and information exchange.
Storage of XML Data XML data can be stored in –Non-relational data stores Flat files –Natural for storing XML –But has all problems discussed in Chapter.
L13-S1 XML 2003 SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José State.
Introduction to XML This material is based heavily on the tutorial by the same name at
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
XML Query Languages Notes Based on Chapter 10 of Database System Concepts.
4/20/2017.
Object-Based Databases. 2 Complex Data Types and Object Orientation Structured Data Types and Inheritance in SQL Table Inheritance Array and Multiset.
Object-Relational Databases By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
©Silberschatz, Korth and SudarshanDatabase System Concepts.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 1: Introduction.
Database System Concepts ©Silberschatz, Korth and Sudarshan Database System Concepts Chapter 9: Object-Based Databases.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-02,03 Introduction –Data Models Lectured by, Jesmin Akhter.
Chapter 10: XML. ©Silberschatz, Korth and Sudarshan10.2Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium.
Lecture 7 of Advanced Databases XML Querying & Transformation Instructor: Mr.Ahmed Al Astal.
©Silberschatz, Korth and Sudarshan8.1Database System Concepts Chapter 8: Object-Oriented Databases New Database Applications The Object-Oriented Data Model.
 Structure of XML Data  XML Document Schema  Querying and Transformation  Application Program Interfaces to XML  Storage of XML Data  XML Applications.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
©Silberschatz, Korth and Sudarshan10.1Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium (W3C) Originally.
XML By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Chapter 10: XML.
Lecture 6 of Advanced Databases XML Querying & Transformation Instructor: Mr.Eyad Almassri.
Computing & Information Sciences Kansas State University Friday, 17 Oct 2007CIS 560: Database System Concepts Lecture 21 of 42 Friday, 17 October 2008.
Chapter 10: XML XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data.
XMLI Structure of XML Data Structure of XML Data XML Document Schema XML Document Schema XPATH XPATH.
XML. 2 XML- Some Links XML Tutorials – Some Links me=htmlhttp://
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
Computing & Information Sciences Kansas State University Thursday, 15 Mar 2007CIS 560: Database System Concepts Lecture 24 of 42 Thursday, 15 March 2007.
©Silberschatz, Korth and Sudarshan9.1Database System Concepts Chapter 9: Object-Oriented Databases Nested Relations Complex Types and Object Orientation.
©Silberschatz, Korth and Sudarshan1Database System Concepts Lecture 7: Introduction to Database Management Systems - Object-Oriented Databases Lecturer:
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
Temple University – CIS Dept. CIS616– Principles of Data Management V. Megalooikonomou XML ( based on slides by Silberschatz, Korth and Sudarshan at Bell.
XML Name: Niki Sardjono Class: CS 157A Instructor : Prof. S. M. Lee.
Chapter 23 XML. 2 Introduction  XML: eXtensible Markup Language (What is a Markup language?)  Defined by the WWW Consortium (W3C)  Originally intended.
Database System Concepts Bin Mu at Tongji University Chapter 10: XML.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
CIS750 – Seminar in Advanced Topics in Computer Science Advanced topics in databases – Multimedia Databases V. Megalooikonomou XML ( based on slides by.
1. XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data XML Applications.
ADT 2010 Introduction to XML, XPath (& XQuery) Chapter 10 in Silberschatz, Korth, Sudarshan “Database System Concepts” Stefan Manegold
Computing & Information Sciences Kansas State University Friday, 20 Oct 2006CIS 560: Database System Concepts Lecture 24 of 42 Friday, 20 October 2006.
Introduction to DTD A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Other Topics 1: Object.
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 10: XML.
Chapter 10: XML. XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data XML.
Chapter 8: XML. 2 XML Structure of XML Data XML Document Schema Querying and Transformation Application Program Interfaces to XML Storage of XML Data.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 10: XML.
Chapter 10: XML. ©Silberschatz, Korth and Sudarshan10.2Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium.
Chapter 10: XML. ©Silberschatz, Korth and Sudarshan10.2Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium.
L14-S1 XML 2003 SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José State.
Chapter 10: XML Introduction  XML: Extensible Markup Language  Defined by the WWW Consortium (W3C)  Originally intended as a document.
©Silberschatz, Korth and Sudarshan 1.1 Database System Concepts قواعد البيانات Data Base قواعد البيانات CCS 402 Mr. Nedal hayajneh E- mail
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 1: Introduction.
Object Relational Databases
10.1 Chapter 10: XML Sections Problems 10.1, 10.2, 10.7 Find an example of using XML in a field of interest to you and describe it to the class.
CS 480: Database Systems Lecture 26 March 18, 2013.
Object-Oriented Databases By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
XML: Extensible Markup Language
Querying and Transforming XML Data
XML By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Object-Oriented Databases
XML and Databases.
Structured Types (9-12-2) Structured types allow composite attributes of E-R diagrams to be represented directly. Unnamed row types can also be used in.
Presentation transcript:

©Silberschatz, Korth and Sudarshan8.1Database System Concepts Chapter 8: Object-Oriented Databases Need for Complex Data Types The Object-Oriented Data Model Object-Oriented Languages Persistent Programming Languages Persistent C++ Systems

©Silberschatz, Korth and Sudarshan8.2Database System Concepts Need for Complex Data Types Traditional database applications in data processing had conceptually simple data types  Relatively few data types, first normal form holds Complex data types have grown more important in recent years  E.g. Addresses can be viewed as a  Single string, or  Separate attributes for each part, or  Composite attributes (which are not in first normal form)  E.g. it is often convenient to store multivalued attributes as-is, without creating a separate relation to store the values in first normal form Applications  computer-aided design, computer-aided software engineering  multimedia and image databases, and document/hypertext databases.

©Silberschatz, Korth and Sudarshan8.3Database System Concepts Object-Oriented Data Model Loosely speaking, an object corresponds to an entity in the E- R model. The object-oriented paradigm is based on encapsulating code and data related to an object into single unit. The object-oriented data model is a logical data model (like the E-R model). Adaptation of the object-oriented programming paradigm (e.g., Smalltalk, C++) to database systems.

©Silberschatz, Korth and Sudarshan8.4Database System Concepts Object Structure An object has associated with it:  A set of variables that contain the data for the object. The value of each variable is itself an object.  A set of messages to which the object responds; each message may have zero, one, or more parameters.  A set of methods, each of which is a body of code to implement a message; a method returns a value as the response to the message The physical representation of data is visible only to the implementor of the object Messages and responses provide the only external interface to an object. The term message does not necessarily imply physical message passing. Messages can be implemented as procedure invocations.

©Silberschatz, Korth and Sudarshan8.5Database System Concepts Object Classes Similar objects are grouped into a class; each such object is called an instance of its class All objects in a class have the same  Variables, with the same types  message interface  methods The may differ in the values assigned to variables Example: Group objects for people into a person class Classes are analogous to entity sets in the E-R model

©Silberschatz, Korth and Sudarshan8.6Database System Concepts Class Definition Example class employee { /*Variables */ string name; string address; date start-date; int salary; /* Messages */ int annual-salary(); string get-name(); string get-address(); int set-address(string new-address); int employment-length(); }; Methods to read and set the other variables are also needed with strict encapsulation Methods are defined separately  E.g. int employment-length() { return today() – start-date;} int set-address(string new-address) { address = new-address;}

©Silberschatz, Korth and Sudarshan8.7Database System Concepts Inheritance (Cont.) Place classes into a specialization/IS-A hierarchy  variables/messages belonging to class person are inherited by class employee as well as customer Result is a class hierarchy Note analogy with ISA Hierarchy in the E-R model

©Silberschatz, Korth and Sudarshan8.8Database System Concepts Class Hierarchy Definition class person{ stringname; stringaddress: }; class customer isa person { int credit-rating; }; class employee isa person { date start-date; int salary; }; class officer isa employee { int office-number, int expense-account-number, };......

©Silberschatz, Korth and Sudarshan8.9Database System Concepts Example of Multiple Inheritance Class DAG for banking example.

©Silberschatz, Korth and Sudarshan8.10Database System Concepts Object-Oriented Languages Object-oriented concepts can be used in different ways  Object-orientation can be used as a design tool, and be encoded into, for example, a relational database  analogous to modeling data with E-R diagram and then converting to a set of relations)  The concepts of object orientation can be incorporated into a programming language that is used to manipulate the database.  Object-relational systems – add complex types and object-orientation to relational language.  Persistent programming languages – extend object- oriented programming language to deal with databases by adding concepts such as persistence and collections.

End of Chapter

©Silberschatz, Korth and Sudarshan8.12Database System Concepts Chapter 9: Object-Relational Databases Nested Relations Complex Types and Object Orientation Querying with Complex Types Creation of Complex Values and Objects Comparison of Object-Oriented and Object-Relational Databases

©Silberschatz, Korth and Sudarshan8.13Database System Concepts Object-Relational Data Models Extend the relational data model by including object orientation and constructs to deal with added data types. Allow attributes of tuples to have complex types, including non- atomic values such as nested relations. Preserve relational foundations, in particular the declarative access to data, while extending modeling power. Upward compatibility with existing relational languages.

©Silberschatz, Korth and Sudarshan8.14Database System Concepts Example of a Nested Relation Example: library information system Each book has  title,  a set of authors,  Publisher, and  a set of keywords Non-1NF relation books

©Silberschatz, Korth and Sudarshan8.15Database System Concepts 1NF Version of Nested Relation 1NF version of books flat-books

©Silberschatz, Korth and Sudarshan8.16Database System Concepts 4NF Decomposition of Nested Relation Remove awkwardness of flat-books by assuming that the following multivalued dependencies hold:  title author  title keyword  title pub-name, pub-branch Decompose flat-doc into 4NF using the schemas:  (title, author)  (title, keyword)  (title, pub-name, pub-branch)

©Silberschatz, Korth and Sudarshan8.17Database System Concepts 4NF Decomposition of flat–books

©Silberschatz, Korth and Sudarshan8.18Database System Concepts Problems with 4NF Schema 4NF design requires users to include joins in their queries. 1NF relational view flat-books defined by join of 4NF relations:  eliminates the need for users to perform joins,  but loses the one-to-one correspondence between tuples and documents.  And has a large amount of redundancy Nested relations representation is much more natural here.

©Silberschatz, Korth and Sudarshan8.19Database System Concepts Structured and Collection Types Structured types can be declared and used in SQL create type Publisher as (name varchar(20), branch varchar(20)) create type Book as (title varchar(20), author-array varchar(20) array [10], pub-date date, publisher Publisher, keyword-set setof(varchar(20)))  Note: setof declaration of keyword-set is not supported by SQL:1999  Using an array to store authors lets us record the order of the authors Structured types can be used to create tables create table books of Book  Similar to the nested relation books, but with array of authors instead of set

©Silberschatz, Korth and Sudarshan8.20Database System Concepts Structured Types (Cont.) n We can create tables without creating an intermediate type  For example, the table books could also be defined as follows: create table books (title varchar(20), author-array varchar(20) array[10], pub-date date, publisher Publisher keyword-list setof(varchar(20))) n Methods can be part of the type definition of a structured type: create type Employee as ( name varchar(20), salary integer) method giveraise (percent integer) n We create the method body separately create method giveraise (percent integer) for Employee begin set self.salary = self.salary + (self.salary * percent) / 100; end

©Silberschatz, Korth and Sudarshan8.21Database System ConceptsInheritance Suppose that we have the following type definition for people: create type Person (name varchar(20), address varchar(20)) n Using inheritance to define the student and teacher types create type Student under Person (degree varchar(20), department varchar(20)) create type Teacher under Person (salary integer, department varchar(20)) n Subtypes can redefine methods by using overriding method in place of method in the method declaration

©Silberschatz, Korth and Sudarshan8.22Database System Concepts Multiple Inheritance n SQL:1999 does not support multiple inheritance n If our type system supports multiple inheritance, we can define a type for teaching assistant as follows: create type Teaching Assistant under Student, Teacher n To avoid a conflict between the two occurrences of department we can rename them create type Teaching Assistant under Student with (department as student-dept), Teacher with (department as teacher-dept)

©Silberschatz, Korth and Sudarshan8.23Database System Concepts Collection Valued Attributes (Cont.) We can access individual elements of an array by using indices  E.g. If we know that a particular book has three authors, we could write: select author-array[1], author-array[2], author-array[3] from books where title = `Database System Concepts’

©Silberschatz, Korth and Sudarshan8.24Database System Concepts SQL Functions Define a function that, given a book title, returns the count of the number of authors (on the 4NF schema with relations books4 and authors). create function author-count(name varchar(20)) returns integer begin declare a-count integer; select count(author) into a-count from authors where authors.title=name return a=count; end Find the titles of all books that have more than one author. select name from books4 where author-count(title)> 1

©Silberschatz, Korth and Sudarshan8.25Database System Concepts Procedural Constructs n SQL:1999 supports a rich variety of procedural constructs n Compound statement  is of the form begin … end,  may contain multiple SQL statements between begin and end.  Local variables can be declared within a compound statements n While and repeat statements declare n integer default 0; while n < 10 do set n = n+1 end while repeat set n = n – 1 until n = 0 end repeat

©Silberschatz, Korth and Sudarshan8.26Database System Concepts Procedural Constructs (Cont.) n For loop  Permits iteration over all results of a query  E.g. find total of all balances at the Perryridge branch declare n integer default 0; for r as select balance from account where branch-name = ‘Perryridge’ do set n = n + r.balance end for

©Silberschatz, Korth and Sudarshan8.27Database System Concepts Comparison of O-O and O-R Databases Summary of strengths of various database systems: Relational systems  simple data types, powerful query languages, high protection. Persistent-programming-language-based OODBs  complex data types, integration with programming language, high performance. Object-relational systems  complex data types, powerful query languages, high protection. Note: Many real systems blur these boundaries  E.g. persistent programming language built as a wrapper on a relational database offers first two benefits, but may have poor performance.

End of Chapter

Chapter 10: XML

©Silberschatz, Korth and Sudarshan8.30Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium (W3C) Originally intended as a document markup language not a database language  Documents have tags giving extra information about sections of the document  E.g. XML Introduction …  Derived from SGML (Standard Generalized Markup Language), but simpler to use than SGML  Extensible, unlike HTML  Users can add new tags, and separately specify how the tag should be handled for display  Goal was (is?) to replace HTML as the language for publishing documents on the Web

©Silberschatz, Korth and Sudarshan8.31Database System Concepts XML Introduction (Cont.) The ability to specify new tags, and to create nested tag structures made XML a great way to exchange data, not just documents.  Much of the use of XML has been in data exchange applications, not as a replacement for HTML Tags make data (relatively) self-documenting  E.g. A-101 Downtown 500 A-101 Johnson

©Silberschatz, Korth and Sudarshan8.32Database System Concepts XML: Motivation Data interchange is critical in today’s networked world  Examples:  Banking: funds transfer  Order processing (especially inter-company orders)  Scientific data –Chemistry: ChemML, … –Genetics: BSML (Bio-Sequence Markup Language), …  Paper flow of information between organizations is being replaced by electronic flow of information Each application area has its own set of standards for representing information XML has become the basis for all new generation data interchange formats

©Silberschatz, Korth and Sudarshan8.33Database System Concepts XML Motivation (Cont.) Earlier generation formats were based on plain text with line headers indicating the meaning of fields  Similar in concept to headers  Does not allow for nested structures, no standard “type” language  Tied too closely to low level document structure (lines, spaces, etc) Each XML based standard defines what are valid elements, using  XML type specification languages to specify the syntax  DTD (Document Type Descriptors)  XML Schema  Plus textual descriptions of the semantics XML allows new tags to be defined as required  However, this may be constrained by DTDs A wide variety of tools is available for parsing, browsing and querying XML documents/data

©Silberschatz, Korth and Sudarshan8.34Database System Concepts Structure of XML Data Tag: label for a section of data Element: section of data beginning with and ending with matching Elements must be properly nested  Proper nesting  … ….  Improper nesting  … ….  Formally: every start tag must have a unique matching end tag, that is in the context of the same parent element. Every document must have a single top-level element

©Silberschatz, Korth and Sudarshan8.35Database System Concepts Example of Nested Elements Hayes Main Harrison A-102 Perryridge 400 …..

©Silberschatz, Korth and Sudarshan8.36Database System Concepts Motivation for Nesting Nesting of data is useful in data transfer  Example: elements representing customer-id, customer name, and address nested within an order element Nesting is not supported, or discouraged, in relational databases  With multiple orders, customer name and address are stored redundantly  normalization replaces nested structures in each order by foreign key into table storing customer name and address information  Nesting is supported in object-relational databases But nesting is appropriate when transferring data  External application does not have direct access to data referenced by a foreign key

©Silberschatz, Korth and Sudarshan8.37Database System Concepts Structure of XML Data (Cont.) Mixture of text with sub-elements is legal in XML.  Example: This account is seldom used any more. A-102 Perryridge 400  Useful for document markup, but discouraged for data representation

©Silberschatz, Korth and Sudarshan8.38Database System ConceptsAttributes Elements can have attributes  A-102 Perryridge 400 Attributes are specified by name=value pairs inside the starting tag of an element An element may have several attributes, but each attribute name can only occur once 

©Silberschatz, Korth and Sudarshan8.39Database System Concepts Attributes Vs. Subelements Distinction between subelement and attribute  In the context of documents, attributes are part of markup, while subelement contents are part of the basic document contents  In the context of data representation, the difference is unclear and may be confusing  Same information can be represented in two ways – …. – A-101 …  Suggestion: use attributes for identifiers of elements, and use subelements for contents

©Silberschatz, Korth and Sudarshan8.40Database System Concepts More on XML Syntax Elements without subelements or text content can be abbreviated by ending the start tag with a /> and deleting the end tag  To store string data that may contain tags, without the tags being interpreted as subelements, use CDATA as below  … ]]>  Here, and are treated as just strings

©Silberschatz, Korth and Sudarshan8.41Database System Concepts XML Document Schema Database schemas constrain what information can be stored, and the data types of stored values XML documents are not required to have an associated schema However, schemas are very important for XML data exchange  Otherwise, a site cannot automatically interpret data received from another site Two mechanisms for specifying XML schema  Document Type Definition (DTD)  Widely used  XML Schema  Newer, not yet widely used

©Silberschatz, Korth and Sudarshan8.42Database System Concepts Document Type Definition (DTD) The type of an XML document can be specified using a DTD DTD constraints structure of XML data  What elements can occur  What attributes can/must an element have  What subelements can/must occur inside each element, and how many times. DTD does not constrain data types  All values represented as strings in XML DTD syntax 

©Silberschatz, Korth and Sudarshan8.43Database System Concepts Element Specification in DTD Subelements can be specified as  names of elements, or  #PCDATA (parsed character data), i.e., character strings  EMPTY (no subelements) or ANY (anything can be a subelement) Example Subelement specification may have regular expressions  Notation: – “|” - alternatives – “+” - 1 or more occurrences – “*” - 0 or more occurrences

©Silberschatz, Korth and Sudarshan8.44Database System Concepts Bank DTD <!DOCTYPE bank [ ]>

©Silberschatz, Korth and Sudarshan8.45Database System Concepts XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports  Typing of values  E.g. integer, string, etc  Also, constraints on min/max values  User defined types  Is itself specified in XML syntax, unlike DTDs  More standard representation, but verbose  Is integrated with namespaces  Many more features  List types, uniqueness and foreign key constraints, inheritance.. BUT: significantly more complicated than DTDs, not yet widely used.

©Silberschatz, Korth and Sudarshan8.46Database System Concepts XML Schema Version of Bank DTD ….. definitions of customer and depositor ….

©Silberschatz, Korth and Sudarshan8.47Database System Concepts Querying and Transforming XML Data Translation of information from one XML schema to another Querying on XML data Above two are closely related, and handled by the same tools Standard XML querying/translation languages  XPath  Simple language consisting of path expressions  XSLT  Simple language designed for translation from XML to XML and XML to HTML  XQuery  An XML query language with a rich set of features Wide variety of other languages have been proposed, and some served as basis for the Xquery standard  XML-QL, Quilt, XQL, …

©Silberschatz, Korth and Sudarshan8.48Database System Concepts Tree Model of XML Data Query and transformation languages are based on a tree model of XML data An XML document is modeled as a tree, with nodes corresponding to elements and attributes  Element nodes have children nodes, which can be attributes or subelements  Text in an element is modeled as a text node child of the element  Children of a node are ordered according to their order in the XML document  Element and attribute nodes (except for the root node) have a single parent, which is an element node  The root node has a single child, which is the root element of the document We use the terminology of nodes, children, parent, siblings, ancestor, descendant, etc., which should be interpreted in the above tree model of XML data.

©Silberschatz, Korth and Sudarshan8.49Database System ConceptsXPath XPath is used to address (select) parts of documents using path expressions A path expression is a sequence of steps separated by “/”  Think of file names in a directory hierarchy Result of path expression: set of values that along with their containing elements/attributes match the specified path E.g. /bank-2/customer/name evaluated on the bank-2 data we saw earlier returnsbank-2 data Joe Mary E.g. /bank-2/customer/name/text( ) returns the same names, but without the enclosing tags

©Silberschatz, Korth and Sudarshan8.50Database System ConceptsXSLT A stylesheet stores formatting options for a document, usually separately from document  E.g. HTML style sheet may specify font colors and sizes for headings, etc. The XML Stylesheet Language (XSL) was originally designed for generating HTML from XML XSLT is a general-purpose transformation language  Can translate XML to XML, and XML to HTML XSLT transformations are expressed using rules called templates  Templates combine selection using XPath with construction of results

©Silberschatz, Korth and Sudarshan8.51Database System ConceptsXQuery XQuery is a general purpose query language for XML data Currently being standardized by the World Wide Web Consortium (W3C)  The textbook description is based on a March 2001 draft of the standard. The final version may differ, but major features likely to stay unchanged. Alpha version of XQuery engine available free from Microsoft XQuery is derived from the Quilt query language, which itself borrows from SQL, XQL and XML-QL XQuery uses a for … let … where.. result … syntax for  SQL from where  SQL where result  SQL select let allows temporary variables, and has no equivalent in SQL

©Silberschatz, Korth and Sudarshan8.52Database System Concepts FLWR Syntax in XQuery For clause uses XPath expressions, and variable in for clause ranges over values in the set returned by XPath Simple FLWR expression in XQuery  find all accounts with balance > 400, with each result enclosed in an.. tag for $x in /bank-2/account let $acctno := where $x/balance > 400 return $acctno Let clause not really needed in this query, and selection can be done In XPath. Query can be written as: for $x in /bank-2/account[balance>400] return

©Silberschatz, Korth and Sudarshan8.53Database System Concepts Storage of XML Data XML data can be stored in  Non-relational data stores  Flat files –Natural for storing XML –But has all problems discussed in Chapter 1 (no concurrency, no recovery, …)  XML database –Database built specifically for storing XML data, supporting DOM model and declarative querying –Currently no commercial-grade systems  Relational databases  Data must be translated into relational form  Advantage: mature database systems  Disadvantages: overhead of translating data and queries

©Silberschatz, Korth and Sudarshan8.54Database System Concepts Storing XML in Relational Databases Store as string  E.g. store each top level element as a string field of a tuple in a database  Use a single relation to store all elements, or  Use a separate relation for each top-level element type –E.g. account, customer, depositor –Indexing: »Store values of subelements/attributes to be indexed, such as customer-name and account-number as extra fields of the relation, and build indices »Oracle 9 supports function indices which use the result of a function as the key value. Here, the function should return the value of the required subelement/attribute  Benefits:  Can store any XML data even without DTD  As long as there are many top-level elements in a document, strings are small compared to full document, allowing faster access to individual elements.  Drawback: Need to parse strings to access values inside the elements; parsing is slow.

©Silberschatz, Korth and Sudarshan8.55Database System Concepts Storing XML as Relations (Cont.) Tree representation: model XML data as tree and store using relations nodes(id, type, label, value) child (child-id, parent-id)  Each element/attribute is given a unique identifier  Type indicates element/attribute  Label specifies the tag name of the element/name of attribute  Value is the text value of the element/attribute  The relation child notes the parent-child relationships in the tree  Can add an extra attribute to child to record ordering of children  Benefit: Can store any XML data, even without DTD  Drawbacks:  Data is broken up into too many pieces, increasing space overheads  Even simple queries require a large number of joins, which can be slow

©Silberschatz, Korth and Sudarshan8.56Database System Concepts Storing XML in Relations (Cont.) Map to relations  If DTD of document is known, can map data to relations  Bottom-level elements and attributes are mapped to attributes of relations  A relation is created for each element type  An id attribute to store a unique id for each element  all element attributes become relation attributes  All subelements that occur only once become attributes –For text-valued subelements, store the text as attribute value –For complex subelements, store the id of the subelement  Subelements that can occur multiple times represented in a separate table –Similar to handling of multivalued attributes when converting ER diagrams to tables  Benefits:  Efficient storage  Can translate XML queries into SQL, execute efficiently, and then translate SQL results back to XML  Drawbacks: need to know DTD, translation overheads still present