Você está na página 1de 26

An XML Enablement of DB2

-- DB2 XML Extender

Manfred Pler

Jane Xu and Josephine Cheng

IBM Datamanagement

Database Technology Institute,

mpaessle@us.ibm.com

Silicon Valley Lab, IBM


jxu@us.ibm.com

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

Agenda
XML and DB2
XML Extender Overview
Storage and Access of XML Documents
XML Processing of Relational Data
Other Features
Conclusions

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

XML and DB2

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

XML completes the puzzle


XML brings data to the web, completing the
necessary components for 90%+ of
e-business applications.
Universal Communication - Internet
Universal User Interface - Browsers
Universal Programming - Java
and now...

Universal Information - XML

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

Putting DB2's Power to Support XML


DB2 provides stability, scalability, and security
Your mission-critical business data is currently
stored in DB2
DB2's XML support adds its power to enable your
business data for XML
With DB2's XML support, you can make
applications to:
Store XML documents for fast search
Compose or decompose XML documents from or
into relational tables
Query XML data based on XPath expressions

You can build B2B and B2C applications on top


of DB2 using XML Extender as the SDK
Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

XML Extender Overview

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

XML Extender Overview

File System

Application
Program

DAD
(Data Access
Definition)

XML
DOC

Xu and Cheng, Pler

DB2 XML
Extender

XML
Files

DB2

NET.OBJET DAYS 2000 October 10-12, 2000

Two Access and Storage Methods

DAD
(Data Access
Definition)

Application

DB2 UDB

DB2 XML
Extender

XML
Collection

XML
Column
user table
book

XML
DOC

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

XML Extender Components


Server

Client
DB2
CAE

DB2
Server

XML Extender
Client

XML Extender
Server

Admin
GUI

Stored
procedures

Utilities

UDFs

XML
Parser

Admin
Command

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

DAD: Data Access Definition


XML document itself
Define the mapping between XML document and
relational tables
Used for both XML Column and XML Collection
XPath Standard:
XPath:
part of the XSLT, as W3C recommendation
A subset of the abbreviated location paths is used
to identify XML element or attribute
The data model is used in XML collection mapping.

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

10

Storage and Access of XML


Documents

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

11

XML Column Storage and Access


UDT (DB2 User Defined Type):
XMLFile - external file name
XMLVarchar - for internal short document
XMLCLOB - for internal long document

UDF (DB2 User Defined Function):


Import/Storage
Retrieval
Update
Extract:
Extract XML element/attribute values from
documents
Convert characters in XML documents into general
SQL data types
Provide both scalar and table UDFs for each data
type
Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

12

Extracting UDF Examples


invoice_number

order

355 ...
356 ...<Order>...<Part>...<ExtendedPrice>1000</...
357 ...

Select
db2xml.extractDouble(order,'/Order/Part/ExtendedPrice')
from order_tab where invoice_number = 356
<book><chapter id="1">...</...><footnote id="2">...</...
Select * from table(db2xml.extractIntegers(
db2xml.XMLFile('c:\dxx\samples\xml\book1.xml'),
'/book/*/@id')) as x;
Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

13

Using Side Tables for Fast Searches in


XML Documents

<order key='99'>
<customer>Thompson</customer>
<part key='82'> .... </part>
<part key='83'> .... </part>
</order>

DAD
(Data Access
Definition)

Sales_tab

...

Order
(XMLCLOB)

...

side tables
order_tab
order_key customer

...

Xu and Cheng, Pler

...

99

Thompson

part_tab
part_key

....

82

....

83

....

NET.OBJET DAYS 2000 October 10-12, 2000

14

Use Text Extender on Structural Text


Search
XML column or decomposed column in tables can be
enabled with Text Extender
Use Text Extender section support of structural text
search in query
Example:
SELECT order FROM sales_table
WHERE CONTAINS(orderHandle,
'MODEL order SECTION(/Order/Customer)
"John Doe" ') = 1
No dependency on Text Extender if searching on SQL
data types of XML element/attribute values is sufficient

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

15

XML Processing of
Relational Data

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

16

Document/Database Mapping with DAD


<order key='99'>
<customer>Thompson</customer>
<part key='82' > .... </part>
<part key='83' > .... </part>
</order>
Mapping Methods:
DAD
(Data Access
Definition)

99

Xu and Cheng, Pler

customer
Thompson

compostion/decomposition)

part_tab

order_tab
order_key

SQL (compostion only)


RDB_node (XML-Style for

order_key

part_key

....

99

82

....

99

83

....

NET.OBJET DAYS 2000 October 10-12, 2000

17

Two Mapping Schemes


SQL mapping (composition only)
SQL syntax
specify the SQL select statement
specify the mapping between column and XML data
in attribute_node and text_node
certain restrictions apply

RDB_node mapping (comp. & decomp.)


XML syntax
specify tables and relationship among tables in the
RDB_node of the root element_node
specify RDB_node with table name, column name
and optional condition for attribute_node and
text_node

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

18

Dynamic Mapping
Ability to take DAD to generate or shred XML
documents, where DAD can be created by
applications on the fly.
Change query criteria by overriding query condition
for document generation
SQL_OVERRIDE:
replace the SQL query
change conditions in the WHERE clause
designed for DBMS experts
XML_OVERRIDE:
Use XPath syntax to define element or attribute,
Specify the constraints on XML elements or
attributes on the documents to be generated
An example:
/department/@id
= 'E01'
AND
/department/name = 'John Duo'
Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

19

Use Stored Procedures to Process


XML Collections
Decompose XML documents into new or existing
tables
Compose XML documents from existing data or
decomposed XML documents
Specify override type and value for dynamic
mapping

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

20

Other Features

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

21

Other Features
DTD Repository
Store your DTDs in DB2
One DTD can be referenced by many XML
documents and more than one XML column and
XML collection.
Use DTDID to validate input XML documents at
the insertion time
Validating Input or Generated XML Documents
Validation can be specified in your DAD,
Supported in both XML Column and Collection
features
GUI based Administration Tool
Help enabling your database, tables, columns,
and collections for XML
Help creating DADs
Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

22

Conclusions

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

23

Unique Features of DB2 XML Extender


In XML Column
XPath based queries on individual documents
using extracting UDFs
Use XPath data model to map XML structure to
relational tables
XPath based element/attribute update
Providing Sequence number to identify multiple
occurred XML document element or attribute
In XML Collection
Direct mapping from relational to your target XML
document structure, for high volume B2B
applications
Dynamically generate XML documents from DB2
data, and change query criteria via overriding
query conditions
Decompose XML documents and storing
un-tagged data into DB2 tables
Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

24

For Your e-business Applications


Validate input or generated XML documents against
DTDs
Integrated with DB2 Net.Data for Web applications
Write your applications with the interface of
embedded SQL, ODBC, JDBC, or SQLJ
Integrate XML technology with traditional relational
data
Integrated with DB2 UDB package

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

25

Availability
Shipped as part of the DB2 Family
Platforms:
AIX, NT, Solaris, Lnix Shiped with DB2 UDB V7.1
AS/400 and OS/390 will be available soon

Web site
http://www.software.ibm.com/data/db2/
extenders/xmlext/index.html
Contact DB2XML@us.ibm.com for more
information

Xu and Cheng, Pler

NET.OBJET DAYS 2000 October 10-12, 2000

26

Você também pode gostar