XMLII XSchema XSchema XQuery XQuery Oracle XSU Oracle XSU.

Slides:



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

XML: Extensible Markup Language
1 XQuery Web and Database Management System. 2 XQuery XQuery is to XML what SQL is to database tables XQuery is designed to query XML data What is XQuery?
Introduction to XML CS348 Information System Guest Lecture Hazem Elmeleegy.
Chapter 10: XML. ©Silberschatz, Korth and Sudarshan10.2Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 10: XML.
1 COS 425: Database and Information Management Systems XML and information exchange.
Misc Topics Amol Deshpande CMSC424. Topics Today  Database system architectures  Client-server  Parallel and Distributed Systems  Object Oriented,
L13-S1 XML 2003 SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José State.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
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.
XML Databases and introducing their languages, XQuery, XSLT, and XPath
2.2 SQL Server 2005 的 XML 支援功能. Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Chapter 10: XML. ©Silberschatz, Korth and Sudarshan10.2Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium.
Computing & Information Sciences Kansas State University Monday. 20 Oct 2008CIS 560: Database System Concepts Lecture 21 of 42 Monday, 20 October 2008.
Lecture 7 of Advanced Databases XML Querying & Transformation Instructor: Mr.Ahmed Al Astal.
 Structure of XML Data  XML Document Schema  Querying and Transformation  Application Program Interfaces to XML  Storage of XML Data  XML Applications.
Lecture 21 XML querying. 2 XSL (eXtensible Stylesheet Language) In HTML, default styling is built into browsers as tag set for HTML is predefined and.
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.
Maziar Sanaii Ashtiani – SCT – EMU, Fall 2011/12.
Lecture 6 of Advanced Databases XML Querying & Transformation Instructor: Mr.Eyad Almassri.
DATABASE and XML Moussa Mané. Learning Objectives ● Learn about Native XML Databases ● Learn about the conversion technology available ● Understand New.
Computing & Information Sciences Kansas State University Friday, 17 Oct 2007CIS 560: Database System Concepts Lecture 21 of 42 Friday, 17 October 2008.
Another PillowTalk Presentation  2004 Dynamic Systems, Inc. Introduction to XML for SOA Lee H. Burstein,
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.
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
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.
Computing & Information Sciences Kansas State University Thursday, 15 Mar 2007CIS 560: Database System Concepts Lecture 24 of 42 Thursday, 15 March 2007.
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 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.
XML and Database.
Database System Concepts Bin Mu at Tongji University Chapter 10: XML.
XML e X tensible M arkup L anguage (XML) By: Albert Beng Kiat Tan Ayzer Mungan Edwin Hendriadi.
CIS750 – Seminar in Advanced Topics in Computer Science Advanced topics in databases – Multimedia Databases V. Megalooikonomou XML ( based on slides by.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
©Silberschatz, Korth and Sudarshan10.1Database System Concepts XML Query Languages Notes Based on Chapter 10 of Database System Concepts.
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.
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.
Experience with XML Schema Ashok Malhotra Schema Usage  Mapping XML Schema and XML documents controlled by the Schema to object classes and instances.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 10: XML.
Copyright 2002, Ronald Bourret, XML-DBMS Middleware for XML and databases Ronald Bourret O'Reilly Open.
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.
D Copyright © 2004, Oracle. All rights reserved. Using Oracle XML Developer’s Kit.
Chapter 10: XML Introduction  XML: Extensible Markup Language  Defined by the WWW Consortium (W3C)  Originally intended as a document.
11 Copyright © 2004, Oracle. All rights reserved. Managing XML Data in an Oracle 10g Database.
ADT 2010 Introduction to (XML, XPath &) XQuery Chapter 10 in Silberschatz, Korth, Sudarshan “Database System Concepts” Stefan Manegold
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.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 10: XML.
CS 480: Database Systems Lecture 26 March 18, 2013.
XML: Extensible Markup Language
Querying and Transforming XML Data
XML By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
CS 480: Database Systems Lecture 28 March 22, 2013.
Chapter 10: XML.
Chapter 10: XML.
Presentation transcript:

XMLII XSchema XSchema XQuery XQuery Oracle XSU Oracle XSU

XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports Typing of values Typing of values E.g. integer, string, etc E.g. integer, string, etc Also, constraints on min/max values Also, constraints on min/max values User-defined, complex types User-defined, complex types Many more features, including Many more features, including uniqueness and foreign key constraints, inheritance uniqueness and foreign key constraints, inheritance XML Schema is itself specified in XML syntax, unlike DTDs XML Schema is itself specified in XML syntax, unlike DTDs More-standard representation, but verbose More-standard representation, but verbose XML Scheme is integrated with namespaces XML Scheme is integrated with namespaces BUT: XML Schema is significantly more complicated than DTDs. BUT: XML Schema is significantly more complicated than DTDs.

XML Schema Version of Bank DTD </xs:element> ….. definitions of customer and depositor …. </xs:sequence></xs:complexType></xs:schema>

XML Schema Version of Bank DTD Choice of “xs:” was ours -- any other namespace prefix could be chosen Choice of “xs:” was ours -- any other namespace prefix could be chosen Element “bank” has type “BankType”, which is defined separately Element “bank” has type “BankType”, which is defined separately xs:complexType is used later to create the named complex type “BankType” xs:complexType is used later to create the named complex type “BankType” Element “account” has its type defined in-line Element “account” has its type defined in-line

More features of XML Schema Attributes specified by xs:attribute tag: Attributes specified by xs:attribute tag: adding the attribute use = “required” means value must be specified adding the attribute use = “required” means value must be specified

Querying and Transforming XML Data Translation of information from one XML schema to another Translation of information from one XML schema to another Querying on XML data Querying on XML data Above two are closely related, and handled by the same tools Above two are closely related, and handled by the same tools Standard XML querying/translation languages Standard XML querying/translation languages XPath XPath Simple language consisting of path expressions Simple language consisting of path expressions XSLT XSLT Simple language designed for translation from XML to XML and XML to HTML Simple language designed for translation from XML to XML and XML to HTML XQuery XQuery An XML query language with a rich set of features An XML query language with a rich set of features

XQuery XQuery is a general purpose query language for XML data XQuery is a general purpose query language for XML data Standardized by the World Wide Web Consortium (W3C) Standardized by the World Wide Web Consortium (W3C) XQuery is derived from the Quilt query language, which itself borrows from SQL, XQL and XML-QL XQuery is derived from the Quilt query language, which itself borrows from SQL, XQL and XML-QL XQuery uses a for … let … where … order by …result … syntax for  SQL from where  SQL where order by  SQL order by XQuery uses a for … let … where … order by …result … syntax for  SQL from where  SQL where order by  SQL order by result  SQL select let allows temporary variables, and has no equivalent in SQL result  SQL select let allows temporary variables, and has no equivalent in SQL

FLWOR Syntax in XQuery For clause uses XPath expressions, and variable in for clause ranges over values in the set returned by XPath For clause uses XPath expressions, and variable in for clause ranges over values in the set returned by XPath Simple FLWOR expression in XQuery Simple FLWOR expression in XQuery find all accounts with balance > 400, with each result enclosed in an.. tag for $x in /bank-1/customer/account let $acctno := $x/account_number/text() find all accounts with balance > 400, with each result enclosed in an.. tag for $x in /bank-1/customer/account let $acctno := $x/account_number/text() where $x/balance > 400 return { $acctno } where $x/balance > 400 return { $acctno } Items in the return clause are XML text unless enclosed in {}, in which case they are evaluated Items in the return clause are XML text unless enclosed in {}, in which case they are evaluated Let clause not really needed in this query, and selection can be done In XPath. Query can be written as: Let clause not really needed in this query, and selection can be done In XPath. Query can be written as: for $x in /bank-1/customer/account[balance>400] return { $x/account_number }

Joins Joins are specified in a manner very similar to SQL for $a in /bank/account, Joins are specified in a manner very similar to SQL for $a in /bank/account, $c in /bank/customer, $c in /bank/customer, $d in /bank/depositor $d in /bank/depositor where $a/account_number = $d/account_number and $c/customer_name = $d/customer_name where $a/account_number = $d/account_number and $c/customer_name = $d/customer_name return { $c $a } return { $c $a } The same query can be expressed with the selections specified as XPath selections: The same query can be expressed with the selections specified as XPath selections: for $a in /bank/account $c in /bank/customer $d in /bank/depositor[ account_number = $a/account_number and customer_name = $c/customer_name ] for $a in /bank/account $c in /bank/customer $d in /bank/depositor[ account_number = $a/account_number and customer_name = $c/customer_name ] return { $c $a } return { $c $a }

Nested Queries The following query converts data from the flat structure for bank information into the nested structure used in bank-1 The following query converts data from the flat structure for bank information into the nested structure used in bank-1 { { for $c in /bank/customer for $c in /bank/customer return return { $c/* } { $c/* } { for $d in /bank/depositor[customer_name = $c/customer_name], { for $d in /bank/depositor[customer_name = $c/customer_name], $a in /bank/account[account_number=$d/account_number] $a in /bank/account[account_number=$d/account_number] return $a } return $a } } } $c/* denotes all the children of the node to which $c is bound, without the enclosing top-level tag $c/* denotes all the children of the node to which $c is bound, without the enclosing top-level tag $c/text() gives text content of an element without any subelements / tags $c/text() gives text content of an element without any subelements / tags

Sorting in XQuery The order by clause can be used at the end of any expression. E.g. to return customers sorted by name for $c in /bank/customer order by $c/customer_name return { $c/* } The order by clause can be used at the end of any expression. E.g. to return customers sorted by name for $c in /bank/customer order by $c/customer_name return { $c/* } Use order by $c/customer_name to sort in descending order Use order by $c/customer_name to sort in descending order Can sort at multiple levels of nesting (sort by customer_name, and by account_number within each customer) Can sort at multiple levels of nesting (sort by customer_name, and by account_number within each customer) { for $c in /bank/customer { for $c in /bank/customer order by $c/customer_name return { $c/* } { for $d in /bank/depositor[customer_name=$c/customer_name], $a in /bank/account[account_number=$d/account_number] } { for $d in /bank/depositor[customer_name=$c/customer_name], $a in /bank/account[account_number=$d/account_number] } order by $a/account_number return $a/* return $a/* } }

Oracle XML-SQL Utility Transform data from o-r tables/views into XML Transform data from o-r tables/views into XML Extract relevant data from an XML document Extract relevant data from an XML document Insert data into database tables Insert data into database tables Using a canonical mapping Using a canonical mapping Available as Available as Java command-line front end Java command-line front end Java API Java API PL/SQL API PL/SQL API

SQL-to-XML Mapping For each SQL query Q, will get the XML file with the following DTD For each SQL query Q, will get the XML file with the following DTD <!DOCTYPE ROWSET[ <!DOCTYPE ROWSET[ ]> ]> If some attribute is of nested table type, then the element will have sub-element corresponding to the attributes of the nested table If some attribute is of nested table type, then the element will have sub-element corresponding to the attributes of the nested table

Example of SQL-to-XML We first create a table country We first create a table country CREATE TABLE country CREATE TABLE country (name char(50), (name char(50), region char(60), region char(60), area decimal(10), area decimal(10), population decimal(11), population decimal(11), gdp decimal(14), gdp decimal(14), primary key (name) primary key (name) ); );

Example of SQL-to-XML CREATE TYPE CountriesType AS OBJECT ( country_name char(50), country_name char(50), area decimal(10), area decimal(10), population decimal(11), population decimal(11), gdp decimal(14) gdp decimal(14));/ CREATE TYPE CountriesTableType AS TABLE OF CountriesType; / CREATE TABLE Regions ( region_name char(60), region_name char(60), countries CountriesTableType, countries CountriesTableType, area decimal(10), area decimal(10), population decimal(11), population decimal(11), gdp decimal(14) gdp decimal(14)) NESTED TABLE Countries STORE AS CountriesTable;

Example of SQL-to-XML INSERT INTO Regions(region_name,area,population,gdp) SELECT region, SUM(area), SUM(population), SUM(gdp) SELECT region, SUM(area), SUM(population), SUM(gdp) FROM country FROM country GROUP BY region; GROUP BY region; UPDATE Regions SET countries = CAST(MULTISET( CAST(MULTISET( SELECT * SELECT * FROM country FROM country WHERE region = Regions.region_name) WHERE region = Regions.region_name) AS CountriesTableType ); AS CountriesTableType );

Example of SQL-to-XML Root – ROWSET element Root – ROWSET element Each row – ROW element Each row – ROW element Each simple attribute – sub-element of ROW element Each simple attribute – sub-element of ROW element Each nested table attribute – sub-element with sub-element Each nested table attribute – sub-element with sub-element Each ROW element has a num attribute Each ROW element has a num attribute Null values are left out Null values are left out

Java front-end utility - OracleXML Export CLASSPATH=/usr/local/oracle/software/jdbc/lib/classes12.zip:/usr/local/oracle/software/rdbms/jlib/xsu11.jar:. java OracleXML getXML \ -user “username/passwd”\ -conn “select * from country” OracleXML parameters OracleXML parameters User name and password User name and password JDBC connection string JDBC connection string SQL query SQL query Extract data from the database to XML form Extract data from the database to XML form

A Few More Options java OracleXML getXML -user ‘user/passwd' -conn \ -conn \ -withDTD -rowsetTag 'countries' -rowTag 'country' -rowIdAttr 'countryID' \ 'select name as gdp, area from country‘ -withDTD -rowsetTag 'countries' -rowTag 'country' -rowIdAttr 'countryID' \ 'select name as gdp, area from country‘ -withDTD: generate the DTD -withDTD: generate the DTD -rowsetTag: specify the rowsetTag name -rowsetTag: specify the rowsetTag name -rowTag: specifiy the rowTag name -rowTag: specifiy the rowTag name -rowIdAttr: specify the name of the row ID attribute of each row -rowIdAttr: specify the name of the row ID attribute of each row name as rename the name sub-element tag to “countryname” tag name as rename the name sub-element tag to “countryname” tag

XSU Java API Through Java API Through Java API Allow generation of XML data Allow generation of XML data Allow insertion of data from an XML document Allow insertion of data from an XML document Allow delete and updates based on XML document Allow delete and updates based on XML document

API classes Oracle.xml.sql.query.OracleXMLQuery (for query) Oracle.xml.sql.query.OracleXMLQuery (for query) Create a JDBC Connection Create a JDBC Connection Create an OracelXMLQUery instance Create an OracelXMLQUery instance Set options in the OracleXMLQuery object Set options in the OracleXMLQuery object Obtain the results Obtain the results Oracle.xml.sql.dml.OracleXMLSave (for update, insert, and delete) Oracle.xml.sql.dml.OracleXMLSave (for update, insert, and delete) Create a JDBC Connection Create a JDBC Connection Creat and OracleXMLSave object Creat and OracleXMLSave object Set options in the OracleXMLSave ojbect Set options in the OracleXMLSave ojbect Invoke the proper method to insert, delete, or update Invoke the proper method to insert, delete, or update

Extracting XML import oracle.jdbc.driver.*; import oracle.xml.sql.query.OracleXMLQuery; import java.lang.*; import java.sql.*; public class xsuGet { public static void main(String[] argv) throws SQLException { public static void main(String[] argv) throws SQLException { try { try { Class.forName ("oracle.jdbc.driver.OracleDriver"); Class.forName ("oracle.jdbc.driver.OracleDriver"); } catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) { System.out.println ("Could not load the driver"); System.out.println ("Could not load the driver"); return; return; } Connection conn = Connection conn = DriverManager.getConnection( DriverManager.getConnection( “username",“passwd"); “username",“passwd"); // Create the query class. // Create the query class. OracleXMLQuery qry = new OracleXMLQuery(conn, "select * from regions"); OracleXMLQuery qry = new OracleXMLQuery(conn, "select * from regions"); // Get the XML string // Get the XML string String str = qry.getXMLString(); String str = qry.getXMLString(); // Print the XML output // Print the XML output System.out.println(" The XML output is:\n"+str); System.out.println(" The XML output is:\n"+str); qry.close(); qry.close(); conn.close(); conn.close(); }}

XMLType A system defined object A system defined object With built in member functions With built in member functions Create, extract, and index XML data Create, extract, and index XML data Can be used as column type Can be used as column type

Define a table with XMLType CREATE TABLE addrbook( name varchar(20), name varchar(20), card SYS.XMLTYPE, card SYS.XMLTYPE, creationDate Date creationDate Date); Address book has a name, a creationData, and a XMLType attribute to contain the contact information structured in XML format Address book has a name, a creationData, and a XMLType attribute to contain the contact information structured in XML format

XMLType Insertion Use member function createXML(‘xml data’); Example: Use member function createXML(‘xml data’); Example: insert into addrbook values ('Roger', sys.XMLType.createXML( ('Roger', sys.XMLType.createXML( ' ' Main Street 123 Main Street Atlanta Atlanta GA GA '), sysdate); '), sysdate); Non-well-formed XML will be rejected

Querying XML Data Use member function: Use member function: getClobVal CLOB (Character Large Object) getClobVal CLOB (Character Large Object) getStringVal getStringVal GetNumberVal GetNumberVal Extract(‘Xpath expression’) Extract(‘Xpath expression’) Example: Example: select a.card.extract('/ACARD').getstringVal() from addrbook a where name = 'Roger';