Pure XML Pertemuan 10 Matakuliah: T0413 Tahun: 2009.

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

XML: Extensible Markup Language
® IBM Software Group © IBM Corporation QUY Thai Duy – ITFac DLU Lesson 15: pureXML – SQL/XML & XQuery.
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?
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
Paper by: A. Balmin, T. Eliaz, J. Hornibrook, L. Lim, G. M. Lohman, D. Simmen, M. Wang, C. Zhang Slides and Presentation By: Justin Weaver.
Agenda from now on Done: SQL, views, transactions, conceptual modeling, E/R, relational algebra. Starting: XML To do: the database engine: –Storage –Query.
XSLT XML DBs, and Schemas Week 18 DSA. The Whisky Case study XSLT can be applied in the client. –Add a xml processing instruction to the xml to bind to.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to Structured Query Language (SQL)
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 DB2 9 Fundamentals.
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
XML and The Relational Data Model
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
Introduction to Structured Query Language (SQL)
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query.
SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence.
4/20/2017.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Module 17 Storing XML Data in SQL Server® 2008 R2.
2.2 SQL Server 2005 的 XML 支援功能. Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery.
XML, distributed databases, and OLAP/warehousing The semantic web and a lot more.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Using XML in SQL Server 2005 NameTitleCompany. XML Overview Business Opportunity The majority of all data transmitted electronically between organizations.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
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.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
Database Technical Session By: Prof. Adarsh Patel.
Sofia, Bulgaria | 9-10 October Using XQuery to Query and Manipulate XML Data Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen.
IBM Almaden Research Center © 2006 IBM Corporation On the Path to Efficient XML Queries Andrey Balmin, Kevin Beyer, Fatma Özcan IBM Almaden Research Center.
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
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.
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
Working with Data Objects Pertemuan 6 Matakuliah: T0413 Tahun: 2009.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
IBM Software Group ® Native XML Support in DB2 Universal Database Matthias Nicola, Bert van der Linden IBM Silicon Valley Lab Sept 1,
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Part VII: XML Querying Software School of Hunan University
Module 18 Querying XML Data in SQL Server® 2008 R2.
Accessing Data Using XML CHAPTER NINE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Copyright© 2005 Oracle Corp.1 SQL/XML Jim Melton USA: Oracle Corp. JTC1 SC32N1632.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
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.
Visual Programing SQL Overview Section 1.
XML and Database.
May 8, :20 a.m. – 10:20 a.m. Platform: DB2 for Linux, UNIX and Windows DB2 9: XML Evolution and Revolution Philip K. Gunning Gunning Technology Solutions,
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
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.
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
Module 3: Using XML. Overview Retrieving XML by Using FOR XML Shredding XML by Using OPENXML Introducing XQuery Using the xml Data Type.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Introduction to Database Programming with Python Gary Stewart
XML: Extensible Markup Language
CHAPTER 7 DATABASE ACCESS THROUGH WEB
CS320 Web and Internet Programming SQL and MySQL
Chapter 6 - Database Implementation and Use
ATS Application Programming: Java Programming
DB2 for Linux, Unix, and Windows
XML in Web Technologies
SQL-1 Week 8-9.
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Database SQL.
Presentation transcript:

Pure XML Pertemuan 10 Matakuliah: T0413 Tahun: 2009

Bina Nusantara University 3 XML Web 2.0SOA Database  DB2 9 XML: The foundation of SOA and Web 2.0

Bina Nusantara University 4 What is DB2’s pureXML technology? Relational Engine XQuery John SQL idnamephone 9John name employee phoneid=901 John XML Engine

Bina Nusantara University 5 What is DB2’s pureXML technology? Two main characteristics: –XML is stored in parsed-hierarchical format in the database –DB2 has a native XML interface to the engine The storage format = the processing format

Bina Nusantara University 6 Native XML Storage XML stored in parsed hierarchical format create table dept (deptID char(8),…, deptdoc xml); Relational columns are stored in relational format (tables) XML columns are stored natively XML stored in UTF8

Bina Nusantara University 7 Integration: Relational and hierarchical data geneX = 987 geneX = 123 NAMESEXAGECOFFEESMOKEDNA ElizabethF RaulM47100 … TinaF58410 PATIENTS table

Bina Nusantara University 8 SQL with Xquery/XPath SELECT name from PATIENTS WHERE xmlexists('$p/Patient/MedicalDetail[geneX="987"]' passing PATIENTS.DNA as "p") and sex = 'F' and age > 55 and coffee > 15 and smoke > 10 ;

Bina Nusantara University 9 pureXML: No need to remap for Data Exchange Applications XML Processing Applications XML Processing XML Exchange Formats:  Web Services  Syndication  Industry Formats Relational And XML DB Relational And XML DB  Storing and querying XML without needing to re-map exchange data to relational format  Providing common integrity, recovery, security, management interfaces and mechanisms  Providing flexibility in the face of schema evolution  Supporting easy access through Web Services and Web 2.0 Edge Company Data

Bina Nusantara University 10 Table definitions with XML columns create table items ( id int primary key not null, brandname varchar(30), itemname varchar(30), sku int, srp decimal(7,2), comments xml ); create table clients( id int primary key not null, name varchar(50), status varchar(10), contact xml );

Bina Nusantara University 11 Insert & Import of XML data INSERT INTO clients VALUES (77, 'John Smith', 'Gold', ' 111 Main St., Dallas, TX, ') ; IMPORT from "C:\DB2workshop\Quicklabs\quicklab14a\clients.del" of del xml from "C:\DB2workshop\Quicklabs\quicklab14a" INSERT INTO CLIENTS (ID, NAME, STATUS, CONTACT); IMPORT from "C:\DB2workshop\Quicklabs\quicklab14a\items.del" of del xml from "C:\DB2workshop\Quicklabs\quicklab14a" INSERT INTO ITEMS (ID, BRANDNAME, ITEMNAME, SKU, SRP, COMMENTS);

Bina Nusantara University 12 John Doe Peter Pan / /dept /dept/employee /dept/employee/name /dept/employee/phone /dept/employee/office (...) Each node has a path XPath dept name employee phoneid=901 John Doe office name employee phoneid=902 Peter Pan office  XML Query Language  Subset of XQuery & SQL/XML

Bina Nusantara University 13 XPath: Simple XPath Expressions Use fully qualified paths to specify elements/attributes is used to specify an attribute use “text()” to specify the text node under an element XPathResult 902 /dept/employee/name Peter Pan John Doe /dept/employee/name/text()Peter Pan John Doe John Doe Peter Pan

Bina Nusantara University 14 XPath: Wildcards * matches any tag name // is the “descendent-or-self” wildcard XPathResult /dept/employee/*/text() John Doe Peter Pan //name/text() Peter Pan John Doe /dept//phone John Doe Peter Pan

Bina Nusantara University 15 XPath:Predicates Predicates are enclosed in square brackets […] Can have multiple predicates in one XPath Positional predicates: [n] selects the n-th child XPathResult Peter Pan >“300”]/name John Doe //employee[office=“344” OR John Doe Peter Pan

Bina Nusantara University 16 XPath: The Parent Axis Current context: “. ” Parent context: “.. ” XPathResult Peter Pan /dept/employee/office[.>“300”] 344 /dept/employee[office > “300”]/office 344 /dept/employee[name=“John 101 /dept/employee/name[.=“John 101 John Doe Peter Pan

Bina Nusantara University 17 XQuery XQuery supports path expressions to navigate XML hierarchical structure XQuery supports both typed and untyped data XQuery lacks null values because XML documents omit missing or unknown data XQuery returns sequences of XML data

Bina Nusantara University 18 XQuery: The FLWOR Expression FOR: iterates through a sequence, bind variable to items LET: binds a variable to a sequence WHERE: eliminates items of the iteration ORDER: reorders items of the iteration RETURN: constructs query results create table dept(deptID char(8),deptdoc xml); xquery for $d in db2-fn:xmlcolumn(‘DEPT.DEPTDOC')/dept let $emp := $d//employee/name where > 95 order by return $emp} John Doe Peter Pan Input:

Bina Nusantara University 19 SQL/XML queries SQL/XML is designed to bridge between the SQL and XML worlds. –Part of the SQL standard includes specifications for embedding XQuery or XPath expressions within SQL statements XPATH is a language for navigating XML documents to find elements or attributes XQuery includes support for XPATH xmlexists function Restricts results based on an XML element value Syntax required prior to DB2 9.5: select name from clients where xmlexists('$c/Client/Address[z ip="95116"]' passing CLIENTS.CONTACT as "c") New syntax allowed with DB2 9.5: select name from clients where xmlexists('$CONTACT/Client/Add ress[zip="95116"]')

Bina Nusantara University 20 select name from clients where xmlexists('$CONTACT/Client/Address[zip="95116"]') SQL is not case sensitive XPath and XQuery are case sensitive! DB2 objects (tables/columns) need to be put in upper case. Example: select name from clients where xmlexists('$contact/Client/Address[zip="95116"]') Case sensitivity - Caution!

Bina Nusantara University 21 SQL, XPath and XQuery use straight quotes (for either single or double quotes depending the situation) Examples: ‘The quotes in this example are curly, which is bad!’ 'The quotes in this example are straight, which is good!' The example below uses curly quotes, so it will fail: It is typical to see this problem when copy/pasting from a Word or Powerpoint document Curly quotes - Caution! xquery db2-fn:xmlcolumn(‘CLIENTS.CONTACT’)/Client/Address[zip=“95116”]

Bina Nusantara University 22 xmlquery function Retrieve one or more element values from our XML document select xmlquery('$CONTACT/Client/ ') from clients where status = 'Gold' Retrieving XML data using “for” and “return” clauses of XQuery SELECT name, xmlquery ('for $e in $CONTACT/Client/ [1] return $e') FROM clients WHERE status = 'Gold'

Bina Nusantara University 23 Retrieving and transforming XML into HTML SELECT xmlquery('for $e in $CONTACT/Client/ [1]/text() return {$e} ') FROM clients WHERE status = 'Gold' select t.comment#,i.itemname,t.customerID,Message from items i, xmltable('$COMMENTS/Comments/Comment' columns Comment# integer path 'CommentID', CustomerID integer path 'CustomerID', Message varchar(100) path 'Message') as t xmltable function: From XML to Relational

Bina Nusantara University 24 xmlelement function: From Relational to XML select xmlelement (name "item",itemname), xmlelement (name "id", id), xmlelement (name "brand",brandname), xmlelement (name "sku",sku) from items where srp < 100 Review: XMLTABLE vs XMLELEMENT XML Relational XMLELEMENT functionXMLTABLE function

Bina Nusantara University 25 Simple XQuery to return customer contact data db2-fn:xmlcolumn is a function with a parameter that identifies the table name and column name of an XML column. xquery db2-fn:xmlcolumn('CLIENTS.CONTACT') FLWOR expression to retrieve client fax data xquery for $y in db2-fn:xmlcolumn('CLIENTS.CONTACT')/Client/fax return $y

Bina Nusantara University 26 Path expression with additional filtering predicate xquery db2-fn:xmlcolumn('CLIENTS.CONTACT')/Client/Address[zip="95116"] Querying DB2 XML data and returning results as HTML xquery { for $y in db2-fn:xmlcolumn('CLIENTS.CONTACT')/Client/Address order by $y/zip return {$y} }

Bina Nusantara University 27 Sample HTML 9407 Los Gatos Blvd. Los Gatos ca El Camino Real Mountain View CA …

Bina Nusantara University 28 Embedded SQL within XQuery xquery for $y in db2-fn:sqlquery('select comments from items where srp > 100')/Comments/Comment where $y/ResponseRequested='Yes' return ( {$y//ProductID} {$y//CustomerID} {$y//Message} ) db2-fn:sqlquery  A function which executes an SQL query and returns only the selected data  The SQL Query passed to db2-fn:sqlquery must return XML data  This XML data can then be further processed by XQuery

Bina Nusantara University 29 Joins with SQL/XML select u.unitID from dept d, unit u where XMLEXISTS ('$e//employee[name = $m] ' passing d.deptdoc as "e", u.manager as "m") create table dept (unitID char(8), deptdoc xml) create table unit (unitID char(8) primary key not null, name char(20), manager varchar(20),... ) select u.unitID from dept d, unit u where u.manager = XMLCAST(XMLQUERY('$e//employee/name' passing d.deptdoc as "e") as char(20))

Bina Nusantara University 30 DELETE operations DELETE a row based on a condition that uses an XML element –Simply use an SQL DELETE statements –A DELETE first searches for the document, and then deletes it. The search part can be done using the same SQL/XML functions as when querying data UPDATE operations With DB2 9, use: –SQL UPDATE statement –or Stored Procedure DB2XMLFUNCTIONS.XMLUPDATE With DB2 9.5: –Use the TRANSFORM expression

Bina Nusantara University 31 Update Example with DB2 9.5: TRANSFORM expression UPDATE purchaseorder SET porder = xmlquery('transform copy $po := $order modify do insert document { Snow Shovel, Super Deluxe 26 inch } into $po/PurchaseOrder return $po' passing purchaseorder.porder as "order") where poid=5012; Adding an element to the end

Bina Nusantara University 32 Update Example with DB2 9.5: TRANSFORM expression UPDATE purchaseorder SET porder = xmlquery('transform copy $po := $order modify do delete $po/PurchaseOrder/item[partid = '' ''] return $po' passing porder as "order") WHERE poid=5012; Deleting an element

Bina Nusantara University 33 XML Indexing Examples create unique index idx1 on customer(info) generate key using xmlpattern as sql double; create index idx2 on customer(info) generate key using xmlpattern '/customerinfo/name' as sql varchar(40); Matt Foreman 1596 Baseline Toronto Ontario M3Z-5H Peter Smith create index idx3 on customer(info) generate key using xmlpattern '//name' as sql varchar(40); create table customer( info XML);

Bina Nusantara University 34 XML Indexing Examples create table customer( info XML); Don’t index everything! Too expensive for insert, update, delete ! Matt Foreman 1596 Baseline Toronto Ontario M3Z-5H Peter Smith create index idx4 on customer(info) generate key using xmlpattern '//text()' as sql varchar(40);

Bina Nusantara University 35 XML Schema Support XML Schemas are supported using “XML Schema repositories” To validate based on an XML Schema you can: –Use the XMLVALIDATE function during an INSERT –Use a BEFORE Trigger To test if an XML document has been validated, you can use the “IS VALIDATED” predicate on a CHECK constraint

Bina Nusantara University 36 DB2 pureXML Schema Flexibility No Schema One Schema Schema V1 Documents Any mix you want! & Schema V2 w/ and w/o schema Document validation for zero, one, or many schemas per XML column: Always Well Formed XML (a) (b) (c) (d) (e) Most databases only support (a) and (b). DB2 9 allows (a) through (e). What does an XML Schema do?