XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302

Slides:



Advertisements
Similar presentations
XML to Relational Database Mapping
Advertisements

XML: Extensible Markup Language
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
CSE 6331 © Leonidas Fegaras XML and Relational Databases 1 XML and Relational Databases Leonidas Fegaras.
Relational Databases for Querying XML Documents: Limitations & Opportunities VLDB`99 Shanmugasundaram, J., Tufte, K., He, G., Zhang, C., DeWitt, D., Naughton,
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
1 COS 425: Database and Information Management Systems XML and information exchange.
XML and DB2 By Josephine Cheng, Jane Xu IBM Santa Teresa Laboratory Slides edited from the original slides of Yunyu Song.
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
XML To Relational Model. Key Index – Forward Traversal Backward Traversal.
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.
Database Systems and XML David Wu CS 632 April 23, 2001.
Storing and Querying Ordered XML Using a Relational Database System By Khang Nguyen Based on the paper of Igor Tatarinov and Statis Viglas.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query.
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.
4/20/2017.
2.2 SQL Server 2005 的 XML 支援功能. Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery.
XML-to-Relational Schema Mapping Algorithm ODTDMap Speaker: Artem Chebotko* Wayne State University Joint work with Mustafa Atay,
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 XML Taken from Chapter 7.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Lecture 7 of Advanced Databases XML Querying & Transformation Instructor: Mr.Ahmed Al Astal.
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.
Maziar Sanaii Ashtiani – SCT – EMU, Fall 2011/12.
Lecture 6 of Advanced Databases XML Querying & Transformation Instructor: Mr.Eyad Almassri.
Extensible Markup and Beyond
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
1 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Introduction to Object-Relational features of Oracle 9i.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
Avoid using attributes? Some of the problems using attributes: Attributes cannot contain multiple values (child elements can) Attributes are not easily.
Efficient XSLT Processing in Relational Database System Zhen Hua Liu Anguel Novoselsky Oracle Corporation VLDB 2006.
Computing & Information Sciences Kansas State University Thursday, 15 Mar 2007CIS 560: Database System Concepts Lecture 24 of 42 Thursday, 15 March 2007.
Nikos dimitrakas – IS4/2i1242/2i4042 spring XML Query Languages Database Systems (4th edition) Chapter 30.5, , Articles & Excerpts.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
XML Name: Niki Sardjono Class: CS 157A Instructor : Prof. S. M. Lee.
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
Copyright© 2005 Oracle Corp.1 SQL/XML Jim Melton USA: Oracle Corp. JTC1 SC32N1632.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
Chapter 23 XML. 2 Introduction  XML: eXtensible Markup Language (What is a Markup language?)  Defined by the WWW Consortium (W3C)  Originally intended.
Chapter 10 Designing the Files and Databases. SAD/CHAPTER 102 Learning Objectives Discuss the conversion from a logical data model to a physical database.
XML STORAGE AND XPATH QUERIES IN ORACLE Jiankai Wu & Joel Poualeu.
XML and Database.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
COMP3030 Database Management System Final Review
Computing & Information Sciences Kansas State University Friday, 20 Oct 2006CIS 560: Database System Concepts Lecture 24 of 42 Friday, 20 October 2006.
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
XML Databases – do they really exist? Jan Erik Kofoed BIBSYS Library Automation ELAG 2005 at CERN, Geneva.
Experience with XML Schema Ashok Malhotra Schema Usage  Mapping XML Schema and XML documents controlled by the Schema to object classes and instances.
Copyright 2002, Ronald Bourret, XML-DBMS Middleware for XML and databases Ronald Bourret O'Reilly Open.
1 Storing and Maintaining Semistructured Data Efficiently in an Object- Relational Database Mo Yuanying and Ling Tok Wang.
SEMI-STRUCTURED DATA (XML) 1. SEMI-STRUCTURED DATA ER, Relational, ODL data models are all based on schema Structure of data is rigid and known is advance.
Before the Relational Model COMP3211 Advanced Databases Dr Nicholas Gibbins –
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Pure XML Pertemuan 10 Matakuliah: T0413 Tahun: 2009.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
XML: Extensible Markup Language
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Relational Databases The Relational Model.
Relational Databases The Relational Model.
Presentation transcript:

XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA III. XML/Database Mappings December 2005

Outline  Introduction  XML Basics  XML Structural Constraint Specification  Document Type Definitions (DTDs)  XML Schema  XML/Database Mappings  XML Parsing APIs  Simple API for XML (SAX)  Document Object Model (DOM)  XML Querying and Transformation  XPath  XQuery  XSLT  XML Applications

Conversion from XML to Objects Straightforward: Main Becomes: (#345, [Name: “Joe”, Age: 44, Address: [Number: 22, Street: “Main”] ] )

Conversion from Objects to XML  Also straightforward  Non-unique:  Always a question if a particular piece (such as Name) should be an element in its own right or an attribute of an element  Example: A reverse translation could give Joe … … … Main This or this

SQL/XML – Extending Reach of SQL to XML Data In the past, SQL was extended with object-oriented features (SQL2) –added values for reference, tuple(row type), and collection(arrays), … –took over ODL and OQL standards of ODMG Currently, SQL is being extended for XML: –adding data types and functions to handle XML –Many vendors have already support for XML and extended SQL to query XML data

Why SQL/XML Publish contents of SQL tables or entire DB as XML documents – need convention for translating primitive SQL data types Create XML documents out of SQL query results – need extension of SQL queries to create XML elements Store XML documents in relational DBs and query them – need extension of SQL to use XPath to access the elements of tree structures

Publishing Relations as XML Documents Current proposal: –no built-in functions to convert tables to XML –but can create arbitrary XML documents using extended SELECT statements Encoding relational data in XML: –Entire relation: an element named after the relation –Each row: an element named row –Each attribute: an element named after the attribute

Publishing Relations as XML Doc: Tables 1024 Bob Smith CS 3093 Amy Doe EE... Professor IdNameDeptId 1024Bob SmithCS 3093Amy DoeEE …

Publishing Relations as XML Documents Professor SQL : CREATE TABLE Professor Id: INTEGER, Name: CHAR(50), DeptId: CHAR(3) XML Schema: <schema xmlns=" targeNamespace="

Publishing Relations as XML Doc: Schema CHAR_len: standard conventions in SQL/XML for CHAR(len) in SQL. –For instance, CHAR_50 is defined as A lot of the SQL/XML standard deals with such data conversion, and with user-defined types of XML, which are defined in SQL using CREATE DOMAIN.

Creating XML from Queries: Functions XMLELEMENT, XMLATTRIBUTES An SQL query does not return XML directly. Produces tables that can have columns of type XML. SELECT SELECT P.Id, XMLELEMENT ( NAME "Prof", -- element name AS XMLATTRIBUTES (P.DeptId AS "Dept"), -- attributes P.Name -- content Info ) AS Info FROM FROM Professor P Produces tuples of the form 1024, Bob Smith 3093, Amy Doe

Creating XML Using Queries: Functions XMLELEMENT, XMLATTRIBUTES XMLELEMENT can be nested: SELECT SELECT XMLELEMENT (NAME "Prof" XMLELEMENT(NAME "Id", P.Id), XMLELEMENT(NAME "Name", P.Name), XMLELEMENT(NAME "DeptId", P.DeptId), ) AS ProfElement FROMProfessor FROM Professor P Produces tuples of the form 1024 Bob Smith CS 3093 Amy Doe EE

Creating XML Using Queries: Function XMLQUERY SELECT XMLQUERY (' {$I} {$N} {$D} '-- template with placeholder variables PASSING BY VALUE P.Id AS I, -- values of I substitute for placehoders P.Name AS N, P.DeptId AS D RETURNING SEQUENCE ProfElement ) AS ProfElement FROM Professor P Placeholder can occur in positions of XML elements and attributes Expressions can be XML-generating expressions or SELECT statements –In the example above, could have SELECT QUERY(‘ {$I} {$N} … ’ PASSING BY VALUE XMLELEMENT(NAME "Id", P.Id) AS I …. In general, the argument to XMLQUERY can include any XQuery expression (XPath or a full query) Can be expressions

Storing XML in Relational DB: Data Type XML Not stored as a string, but natively as a tree structure. Supports navigation via efficient storage and indexing. CREATE TABLE StudentXML ( IdINTEGER, DetailsXML ) where Details attribute contains things of the form Amy Doe U4

Storing XML in Relational DB: Data Type XML To validate, use CREATE TABLE StudentXML ( IdINTEGER, DetailsXML CHECK(Details IS VALID ACCORDING TO SCHEMA ' ) assuming the schema is stored at

Modifying Data in SQL/XML: XMLPARSE XML stored as appropriately indexed tree structure, but in SQL is specified as a sequence of characters – so need to parse: INSERT INTO StudentXML(Id, Details) VALUES (12343, XMLPARSE( ' Bob Smith U4 ' ) )

Modifying Data in SQL/XML: IS VALID ACCORDING TO SCHEMA To validate inserted document: INSERT INTO StudentXML(Id, Details) VALUES(12343, XMLPARSE( ' Bob Smith U4 ‘) IS VALID ACCORDING TO SCHEMA ‘

Querying XML in Relations: Oracle SQL Consider the following relation: create table xorders ( ono number(5) primary key, order SYS.XMLType ); and the following data: insert into xorders values (1020,sys.XMLType.createXML(' DEC DEC '));

Oracle XMLType Querying Get names and street address of customers who have placed orders select distinct c.cname, c.street from xorders o, xcustomers c where c.cno=o.order.extract('/order/customer/text()').getnumberval(); Get number and names of employees who have not taken a single order select e.eno, e.ename from xemployees e where e.eno not in (select o.order.extract('/order/takenBy/text()').getnumberval() from xorders o);

Oracle XMLType Querying Get number and names of customers who have ordered part select distinct c.cno, c.cname from xorders o, xcustomers c where c.cno=o.order.extract( '/order/customer/text()').getnumberval() and instr(o.orderr.extract('/order/items/item/partNumber'), '10601') > 0; Get order number of orders that have not yet shipped (illustrates use of existsNode function) select o.ono from xorders o where o.orderr.existsNode('/order/shippedDate') = 0;

Representing XML using Relations: Shared-Inlining Algorithm Question: Given a DTD (schema), is it possible to map it into an equivalent Relational Schema. Based on node graph constructed for the given DTD –nodes are the elements and attributes –edges are the parent-child relationships Nodes with an in degree of zero (roots!) are made into a separate relation Nodes with an in degree of one are inlined Relational databases do not support set valued attributes – so a separate relation is created for “multiple” occurrences of sub-elements (* and + elements) Each tuple in a relation is uniquely identified by a field called ‘id’ The child relation has a field called ‘parentid’ that references the parent relation’s ‘id’ field

Sample DTD

DTD Node Graph books book library booktitle year booknameheadercolor monthpubdatepub * * Shared-Inlining will produce 3 tables: books, book, and header hdrsize

Relational Schema of that DTD create table books( booksid int, library varchar (25), primary key (booksid) ); create table header( headerid int, hdrsize varchar(25), parentid int, primary key (headerid), foreign key (parentid) references book );

Relational Schema of the DTD create table book( bookid int, author varchar(25), bookname varchar(25), color varchar(25), monthpub varchar(25), datepub varchar(25), parentid int, primary key (bookid), foreign key (parentid) references books );

XML File Marine Bio blue may 18th Mass Comm Orange may 25th

XML File (Contd) Chemistry Red jun 18th Philosophy 20 Grey feb 19th Central Library

Relational Data BOOKSIDLIBRARY 1Central Library Books Table

Relational Data Book table BOOKIDAUTHORBOOKNAMECOLORMONTHPUBDATEPUBPARENTID 1JamesMarine Biology BlueMay18 th 1 2FosterMass Communicatio ns OrangeMay25 th 1 3KimberlyOrganic Chemistry RedJun18 th 1 4JacobPhilosphyGreyFeb19 th 1

Relational Schema Header Table HEADERIDHDRSIZEPARENTID

Translating XML Queries to SQL XPath (will study this later) /books/book/booktitle/bookname the equivalent SQL query is select bookid, bookname, book.parentid from book Answer generated by SQL to XML utility (Oracle 9i) 1 Marine Biology 1...

Translating XML Queries to SQL XPath Query /books/book[booktitle|header|hdrsize='15']/year/monthpub Equivalent SQL query is select bookid,monthpub,book.parentid from book,header where header.hdrsize='15' and header.parentid=book.bookid; Answer generated by SQL to XML utility (Oracle 9i) 3 jun 1