XML and DB2 By Josephine Cheng, Jane Xu IBM Santa Teresa Laboratory Slides edited from the original slides of Yunyu Song.

Slides:



Advertisements
Similar presentations
XML DOCUMENTS AND DATABASES
Advertisements

Tamino – a DBMS Designed for XML Dr. Harald Schoning Presenter: Wenhui Li University of Ottawa Instructed by: Dr. Mengchi Liu Carleton University.
The database approach to data management provides significant advantages over the traditional file-based approach Define general data management concepts.
G O B E Y O N D C O N V E N T I O N WORF: Developing DB2 UDB based Web Services on a Websphere Application Server Kris Van Thillo, ABIS Training & Consulting.
Introduction to Structured Query Language (SQL)
Organizing Data & Information
XML APPLICATIONS Hevel Jean-Baptiste Orson Kirk Kwang Lee Vera Rhoads Dennis Williams.
Introduction to Structured Query Language (SQL)
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Mgt 20600: IT Management & Applications Databases Tuesday April 4, 2006.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Using SQL Queries to Generate XML- Formatted Data Joline Morrison Mike Morrison Department of Computer Science University of Wisconsin-Eau Claire.
Microsoft Access Ervin Ha.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
IST Databases and DBMSs Todd S. Bacastow January 2005.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Chapter 4: Organizing and Manipulating the Data in Databases
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Overview of SQL Server Alka Arora.
XML-to-Relational Schema Mapping Algorithm ODTDMap Speaker: Artem Chebotko* Wayne State University Joint work with Mustafa Atay,
Introduction –All information systems create, read, update and delete data. This data is stored in files and databases. Files are collections of similar.
Systems analysis and design, 6th edition Dennis, wixom, and roth
ASP.NET Programming with C# and SQL Server First Edition
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
DATABASE and XML Moussa Mané. Learning Objectives ● Learn about Native XML Databases ● Learn about the conversion technology available ● Understand New.
Database Solutions for Storing and Retrieving XML Documents.
The McGraw-Hill Companies, Inc Information Technology & Management Thompson Cats-Baril Chapter 3 Content Management.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
RDB/1 An introduction to RDBMS Objectives –To learn about the history and future direction of the SQL standard –To get an overall appreciation of a modern.
Miscellaneous Excel Combining Excel and Access. – Importing, exporting and linking Parsing and manipulating data. 1.
2005 SPRING CSMUIntroduction to Information Management1 Organizing Data John Sum Institute of Technology Management National Chung Hsing University.
Organizing Data and Information AD660 – Databases, Security, and Web Technologies Marcus Goncalves Spring 2013.
Chapter 4: Organizing and Manipulating the Data in Databases
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
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.
Computer Security: Principles and Practice
IBM DB2 UD & XML Extender IBM DB2 UD & XML Extender AstroGrid Project Registry Group Pedro Contreras 14 August 2003.
Nikos dimitrakas – IS4/2i1242/2i4042 spring XML Query Languages Database Systems (4th edition) Chapter 30.5, , Articles & Excerpts.
Introduction to Databases Trisha Cummings. What is a database? A database is a tool for collecting and organizing information. Databases can store information.
CS240A Notes on DB Extenders a.k.a. Data Blades, Cartridge, Snapins Carlo Zaniolo Department of Computer Science University of California, Los Angeles.
1 Design Issues in XML Databases Ref: Designing XML Databases by Mark Graves.
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
6.1 © 2010 by Prentice Hall 6 Chapter Foundations of Business Intelligence: Databases and Information Management.
MANAGING DATA RESOURCES ~ pertemuan 7 ~ Oleh: Ir. Abdul Hayat, MTI.
ITGS Databases.
Creating and Maintaining Geographic Databases. Outline Definitions Characteristics of DBMS Types of database Relational model SQL Spatial databases.
Advanced Accounting Information Systems Day 10 answers Organizing and Manipulating Data September 16, 2009.
Visual Programing SQL Overview Section 1.
XML and Database.
Database Management Supplement 1. 2 I. The Hierarchy of Data Database File (Entity, Table) Record (info for a specific entity, Row) Field (Attribute,
Lecture 10 Creating and Maintaining Geographic Databases Longley et al., Ch. 10, through section 10.4.
Session 1 Module 1: Introduction to Data Integrity
NSF DUE ; Wen M. Andrews J. Sargeant Reynolds Community College Richmond, Virginia.
Presentation on Database management Submitted To: Prof: Rutvi Sarang Submitted By: Dharmishtha A. Baria Roll:No:1(sem-3)
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
uses of DB systems DB environment DB structure Codd’s rules current common RDBMs implementations.
Databases and DBMSs Todd S. Bacastow January
XML: Extensible Markup Language
Fundamentals & Ethics of Information Systems IS 201
Databases and Information Management
MANAGING DATA RESOURCES
Database.
Data Model.
Databases and Information Management
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Databases and Information Management
Presentation transcript:

XML and DB2 By Josephine Cheng, Jane Xu IBM Santa Teresa Laboratory Slides edited from the original slides of Yunyu Song

Outline  Net.Data  XML Extender  Create XML document from DB2  Transform XML document to DB2  Searching XML documents  Conclusion

Net.Data VI  A scripting language to create web applications which can access data from any ODBC compliant databases (e.g. DB2, Oracle, DRDA, ODBC, flat files and web registry data)  Can generate XML documents from SQL queries.  Its successor product is WebSphere Application server.

Generating XML documents from existing DB2 data   Net.Data Macro to generate XML Data

Generating XML documents from existing DB2 data   Resultset of XML data generated by Net.Data

Outline  Net.Data  XML Extender  Create XML document from DB2  Transform XML document to DB2  Searching XML documents  Conclusion

XML Extender  Repository for XML documents and their DTDs.  Data management functionalities (integrity, security, recoverability and management).  User has the option to store the entire document as an column or decomposed into multiple tables and columns.  Users can retrieve the entire document or extract XML elements and attributes dynamically in an SQL query.

XML Collection  SQL Collection Mapping It only works when you can collect all relevant data with a single SELECT statement, which is placed in the DAD. If multiple tables are involved you should use primary- foreign key relationships.  RDB_Node Collection Mapping It allows node definitions for multiple tables. All involved tables must have primary keys. This approach does not require SQL in the DAD. It does allow imports as well as exports.

XML Collection

XML Column  Store entire XML document in a column of XML type  Allows to query XML content  Associate and store DTD in DB2 for one or more document  Map element and attribute to DB2 table (side table)  Used when your XML storage is mainly archival or for reference, and document content is updated infrequently

XML Column

DAD File  Define which DB2 tables hold the data  The mapping method: SQL Collection, RDB Node Collection, or XML Column  Whether to validate XML documents with a DTD before storing or translating the contents  Which DTD to use for validation and translation

Sample DAD (SQL Collection)

Sample DAD ( RDB Node Collection )

Sample DAD (XMLColumn)

XML in DB2

Outline  Net.Data  XML Extender  Create XML document from DB2  Transform XML document to DB2  Searching XML documents  Conclusion

Create XML from DB2  Generate XML fragments (SQL Collection)  Generate whole XML documents (RDB Node Collection)

Generate XML fragments ( SQL Collection ) REC2XML Return XML fragments XMLELEMENT Return Single elements XMLATTRIBUTES Group elements as XML attributes XMLAGG Aggregate elements in a hierarchy

Examples I SELECT XML2CLOB( XMLELEMENT(NAME "Department", XMLATTRIBUTES(e.workdept AS "name"), XMLAGG(XMLELEMENT(NAME "emp", e.lastname) ORDER BY e.lastname) )) AS "dept_list" FROM employee e WHERE e.workdept IN ('C01','E21') GROUP BY workdept This query produces the following output. dept_list <emp>KWAN</emp><emp>NICHOLLS</emp><emp>QUINTANA</emp></Department> <emp>GOUNOT</emp><emp>LEE</emp><emp>MEHTA</emp> SPENSER SPENSER </Department>

Example II  REC2XML Fuction select rec2xml(1.0, 'COLATTVAL','MyRow',DEPTNO, DEPTNAME, MGRNO) AS MYROWS FROM DEPARTMENT MYROWS <MyRow> A00 A00 SPIFFY COMPUTER SERVICE DIV. SPIFFY COMPUTER SERVICE DIV </MyRow><MyRow> B01 B01 PLANNING PLANNING

Compose XML documents ( RDB Node ) dxxGenXML generates an XML document according to the given DAD and places the result in a table you specify used when document update occasionally dxxGenXMLClob identical with dxxGenXML except that it returns the XML directly as a Character Large Object (CLOB) dxxRetrieveXML Used when composing or decomposing XML documents frequently Using the dxxEnableCollection stored procedure to create a named collection and stores the DAD within the database Then refer to it by name using dxxRetrieveXML and dxxRetrieveXMLClob

Examples dxxGenXML(CLOB(100K) DAD, /* input */ char(resultTabName) resultTabName, /* input */ integer overrideType /* input */ integer overrideType /* input */ varchar(1024) override, /* input */ integer maxRows, /* input */ integer numRows, /* output */ long returnCode, /* output */ varchar(1024) returnMsg) /* output */ dxxRetrieveXML(char(collectionName) collectionName, /* input */ char(resultTabName) resultTabName, /* input */ integer overrideType, /* input */ varchar_value override, /* input */ integer maxRows, /* input */ integer numRows, /* output */ long returnCode, /* output */ varchar(1024) returnMsg) /* output */

Outline  Net.Data  XML Extender  Create XML document from DB2  Transform XML document to DB2  Searching XML documents  Conclusion

Transform XML into DB2  XML RDB_Node Collection  XML column

RDB_Node collection  In this case it is the reverse of generating XML from an RDB Node Collection. The end result of this is pure relational data, in tables, and ready to be accessed with the usual database tools. You can do Queries, indexes, views, optimizations etc.  dxxShredXML Takes the DAD as a parameter, similar to dxxGenXML Used for applications that do occasional updates Used for applications that do occasional updates  dxxInsertXML Uses a DAD already stored, similar to dxxRetrieveXML Used for applications that make regular updates Takes an enabled XML collection as input parameter

UDTs provided by XML extender (XML Column) XMLCLOB XML content stored as a character larger object (CLOB) in DB2 XMLVARCHAR XML content stored as VARCHAR in DB2 XMLDBCLOB XML document stored as double byte CLOB in DB2 XMLFILE XML document in a file on a local file system

Store XML as XML Column in DB2 1. Ensure that the database is XML-enabled 2. Optional: Locate or create a DTD for your documents and store it in DB2XML.DTD_REF. 3. Create the table to store the XML documents and add the XML column. Also create any side tables. 4. Create a DAD to map the XML to the relational DB structures. 5. Enable the XML column, specifying the DAD. 6. Create indexes for the side-tables. 7. Insert some XML documents and start performing queries.

Key Features of XML Column I  The XML extender supports a subset of XPath, providing a way to locate specific data within an XML document.  Combined with the provided extracttype functions (extractInteger, extractTimestamp, extractVarChar, etc.) you can retrieve values as database types.

Example I

Example II

Key features of XML Column II  You can select to copy specific element and attribute values to a side table. Doing that lets you search and manipulate the values directly via SQL just like any other column data, linking to the stored XML to pick up related values.  You can create side table indexes, to improve search time.

Use side table for fast search

Key features of XML Column III  XPath based element or attribute update UPDATE sales_tab SET order = Update(order, '/Order/Customer/Name', 'Customer X') WHERE sales_person = 'Salesperson Y' Using the Update function, you can correctly alters both the stored XML document and any relevant side tables.

Outline  Net.Data  XML Extender  Create XML document from DB2  Transform XML document to DB2  Searching XML documents  Conclusion

Searching XML docs ( XML Column )  Example ofXMLColumn

 Using side tables.  Can make a view of the joint. Searching XML documents (Column)

 Example of query against attribute.  The UDF is expensive. Alternatives:  Use DAD to define CUSTOMER as another index in the side table.  Enable XML column to use text indexing (e.g. section search with db2tx.contains). Searching XML documents (Column)

 Search can be done directly against the SQL based tables, or using procedures dxxGenXML() and dxxRetrieveXML().  The DAD is used to specify whether to retrieve the entire document or a fragment.  The DAD is also used to specify the search criteria which can be based either on tables or SQL query. Searching XML documents (Collect)

Outline  Net.Data  XML Extender  Create XML document from DB2  Transform XML document to DB2  Searching XML documents  Conclusion

Conclusion: XML in DB2 RequirementSolutions generate XML document from relational data (DB2 tables) Use simple functions (REC2XML XMLELEMENT etc.) Use a "SQL Collection" to map a query to an XML document structure Use an "RDB Node Collection" to map a number of tables to an XML document structure (this also allows XML import) Use Net.Data Macro to generate XML Data Ignore DB2's capability and use Visual Basic or VB Script Transform XML to relational data Use “RDB_node collection” to store XML in DB2 tables Store XML documents in DB2 Database for later reference Use an "XML Column" to store entire XML documents.They can still be indexed and queried via DB2 functions