xmldb2 PDF
xmldb2 PDF
ABIS
XML document
ABIS
bestsellers
book
bookTitle
Design Patterns
Explained
authorList
author
Alan Shalloway
author
James R. Trott
book
publicationInfo
bookTitle
publisher
year
Addison-Wesley
2001
authorList
publicationInfo
author
publisher
R. Brunner
SAMS
ABIS
Unicode
ABIS
Unicode (..)
Several encodings:
UTF-16 (2 / 4 bytes)
UTF-8 (from 1 to 4 bytes)
ISO-8859-x (1-byte)
etc...
Encoding indicated in xml declaration:
<?xml version="1.0" encoding="UTF-8"?>
ABIS
ABIS
<PLAY>
<TITLE>The Tragedy of Hamlet, Prince of Denmark</TITLE>
<PERSONAE>
<TITLE>Dramatis Personae</TITLE>
<PERSONA>CLAUDIUS, king of Denmark.</PERSONA>
<PERSONA>HAMLET, son to the late, and nephew to the present king.</PERSONA>
<PERSONA>POLONIUS, lord chamberlain.</PERSONA>
<PGROUP>
<PERSONA>VOLTIMAND</PERSONA>
<PERSONA>CORNELIUS</PERSONA>
<PERSONA>ROSENCRANTZ</PERSONA>
<GRPDESCR>courtiers.</GRPDESCR>
</PGROUP>
...
<SPEECH>
<SPEAKER>LORD POLONIUS</SPEAKER>
<LINE>I hear him coming: let's withdraw, my lord.</LINE>
</SPEECH>
<STAGEDIR>Exeunt KING CLAUDIUS and POLONIUS</STAGEDIR>
<STAGEDIR>Enter <PERSONA>HAMLET</PERSONA>, heavily in doubt. </STAGEDIR>
<SPEECH>
<SPEAKER>HAMLET</SPEAKER>
<LINE>To be, or not to be: that is the question:</LINE>
<LINE>Whether 'tis nobler in the mind to suffer</LINE>
<LINE>The slings and arrows of outrageous fortune,</LINE>
<LINE>Or to take arms against a sea of troubles,</LINE>
...
...
</PLAY>
ABIS
<document>
<body>
<heading style=head20_1>Objectives </heading>
<paragraph style=simple>This course consists of 2 parts.</paragraph>
<paragraph style=simple>In the first part, participants will become familiar with
the Enterprise Java (J2EE) platform, the basis for the WebSphere architecture. The
integration of Java with existing (enterprise) systems is also covered.
...
</document>
ABIS
Two standards:
DTD (Document Type Definition)
XML Schema
A set of rules
defining what specific documents should contain on which place
(mandatory and optional things).
Can be used to
validate a document: does it follow the specific rules?
guide you while composing/editing a document
...
Note: well-formedness vs. validity
ABIS
10
DTD example
ABIS
11
Schema Example
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bestsellers">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="bookTitle" type="xs:string"/>
<xs:element name="authorList" >
<xs:complexType>
<xs:sequence>
<xs:element name="author" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="publicationInfo" >
<xs:complexType>
<xs:sequence>
<xs:element name="publisher" type="xs:string"/>
<xs:element name="year" type="xs:string" minOccurs=...
etc ...
ABIS
12
XML by itself!
Powerful definition of
complex structures
data types
ABIS
13
Namespaces
http://www.sas.com/course
course
firstName
name
duration
person
course
name
title
duration
http://www.abis.be
ABIS
14
XML-based standards
ABIS
15
Parsing
application
parser
(DOM or
SAX)
XML
document
E.g.
Microsoft MSXML
Java Xerces
ABIS
16
Transforming
ABIS
17
XSLT
XSL stylesheet:
patterns to search in input document
templates to produce the output document
is XML itself (of course...)
XML
Document
XSL
StyleSheet
XSLT
Processor
XML, HTML,
COBOL,
Java, text, ...
ABIS
18
Searching
XPath:
locating information inside a document
for query, pointing, linking, transformation, schema, ...
XMLQuery (aka XQuery):
powerful querying in document & entire XML databases
emerging standard, many predecessors...
query only
Versions:
XPath 1.0 + XSLT 1.0 (1999)
XPath 2.0 + XSLT 2.0 + XQuery 1.0 (2007)
XSLT versus XQuery: competing standards?
ABIS
19
XPath
ABIS
20
XPath (..)
Example
/
PersonList
Person
Person
Person
FirstName
LastName
Salary
FirstName
LastName
Salary
John
Brussel
12000
Ann
Van Halen
24000
Name
Salary
15000
FirstName
LastName
Josette
's Meyers
ABIS
21
XPath axis
ABIS
22
XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="bestsellers">
<authorList>
<xsl:apply-templates select="//book[@category=fiction"/>
</authorList>
</xsl:template>
<xsl:template match="book">
<xsl:copy-of select="descendant::author"/>
</xsl:template>
</xsl:stylesheet>
ABIS
23
Storing
Main options:
simply as files (*.XML)
in native XML database:
- added support e.g. for querying, transforming, linking
- Tamino, X-Hive, XIS ...
in XML-enabled conventional RDBMS
- DB2, Oracle, SQL Server, ...
- diverse techniques:
stuffing into CLOBs & BLOBs
shredding into colums & tables
- XML as second-class data
ABIS
24
pureXML (Viper)
DB2 as the hybrid database
ABIS
25
pureXML (..)
ABIS
26
Ubiquitous XML
ABIS
27
10
ABIS
28
INSERTing XML
11
PARSING is implicit!
- invoked automatically to check document is well-formed
- to be invoked manually if whitespace in the XML document has to
be preserved
default behaviour: do not preserve!
ABIS
29
register dependant XSDs, ie. XSDs included/imported into the primary one registered above
complete the registration: checks for content of XSD, well-formedness, ...
complete xmlschema customer.xsd
ABIS
30
ABIS
31
SHREDDING
12
ABIS
32
UPDATEing
13
Two ways:
SQL UPDATE: the full XML column!
supplied stored procedure (DB2XMLFUNCTIONS.XMLUPDATE)
XMLUPDATE:
- partial updates to the document in a XML column
- using the stored procedure, supply:
the full XML column to be updated
the XML elements/attributes (in the doc in the column)
to be inserted/updated/deleted
ABIS
33
14
Pure:
plain SQL
plain XQuery
Blended:
SQL/XML ( = SQL with XPath/XQuery inside)
XQuery with SQL inside
ABIS
34
Plain SQL
15
select ocustomer
from orders
where oid = 5;
select oinfo
from orders
where otype in (XE, AB);
use when:
- full document retrieval - no fragments required
- search criteria on non-XML columns
- insert, update, delete of full documents
why not use CLOB, VARCHAR?
DB2 Net search extender available in plain SQL, combined with e.g.
Xpath expressions
relational predicates - insert, update, delete - parameter markers - full text search
function calls
ABIS
35
SQL/XML
16
ABIS
36
XMLTable
ABIS
37
SQL/XML (iii)
advantages
- integration/interaction between SQL and XML based criteria
join based on XML and column criteria
group by only implemented using SQL/XML
- full-text search condition supported
- use of parameter markers
disadvantages
- difficult for transformation purposes, yet ...
xsltransform (-> XSLT stylesheet based transformation)
ABIS
38
XQuery
17
ABIS
39
XQuery (ii)
advantages
- XML only apps; no SQL, relational constructs required
- easy to embed in XML documents to be created
- join, union XML documents
disadvantages
- no DB2 Net search extender support
- no support for parameter markers - yet
- no support for UDFs
ABIS
40
18
ABIS
41
advantages
- based on a valid SQL query
- DB2 Net search extender supported
- integration/interaction between SQL and XML based criteria
- parameter marker support
- UDF support
ABIS
42
>> Optimization
19
- query rewrite
- operator selection
- index selection
- ...
ABIS
43
Optimization (ii)
ABIS
44
Optimization (iii)
- traditional use
- when requesting runstats on XML columns only, statistics describing other column data is maintained!
ABIS
45
20
Hierarchical data
Semi-structured data
Document/narrative data
Many different schemas
Large schemas (with sparsely populated attributes/elements)
Quickly evolving schema
Forms-based applications
Data with nulls & multiple values
Existing industry standard schemas for XML
ABIS
46