Transcript Slide 1

DATABASE and XML
Moussa Mané
Learning Objectives
● Learn about Native XML Databases
● Learn about the conversion technology
available
● Understand New functionality of the
Middleware: MySql 5.1
● Use MySql 5.1 to retrieve and update
information in XML document
Models
XML documents fall into two broad categories:
data-centric and document-centric
● Data-centric documents (for data transport) have fairly
regular structure, order typically does not matter, and
little or no mixed content.
● Document-centric documents (usually for human
consumption) have less regular or irregular structure,
significant order of the elements, and lots of mixed
content.
Native XML Databases
"Defines a (logical) model for an XML
document and stores and retrieves
documents according to that model."
(Bourret, 2002)
Product
Developer
License
DB Type
Tamino
Software AG
Commercial
Proprietary.
Relational
through ODBC.
eXist
Wolfgang Meier
Open Source
Relational
dbXML
dbXML Group
Open Source
Proprietary
Xindice
Apache
Software
Foundation
Open Source
Proprietary
(Model-based)
eXist
● eXist is an Open Source effort to develop a
native XML database system, tightly
integrated with existing XML development
tools like Apache's Cocoon.
● The database may be easily deployed,
running either standalone, inside a servlet
engine, or directly embedded in an
application.
eXist - Features
● Schema-less storage - Documents do not have to be
associated to schema or document type, meaning
they are allowed to be well formed only.
● Collections - A collection plays a similar role to a
directory in a file system. When submitting a query
the user can choose a distinct part of the collection
hierarchy or even all the documents contained in the
database.
● Query languages - The most popular query
languages supported by Native XML databases are
XPath and XQuery.
Relational Databases
Database vendors such as IBM, Microsoft,
Oracle, and Sybase have developed tools to
assist in converting XML documents into
relational tables.
Oracle
● Oracle's XML SQL Utility (XSU) uses a
schematic mapping that defines how to map
tables and views, including object-relational
features, to XML documents.
● Oracle translates the chain of object
references from the database into the
hierarchical structure of XML elements.
Oracle
Creating Table:
Oracle
A corresponding XML
document generated
from the given objectrelational model looks
like:
XSU
XSU can be used for executing queries in a Java
environment and retrieve XML from the database.
XSU
Query Languages
● XPath is a language for addressing parts of
an XML document, and is the common
locator used by both XSLT and XPointer.
●An XPath expression is a series of location
steps separated by " / ". Each step selects a
set of nodes that become the current node(s)
for the next step. The set of nodes selected
by the expression are the nodes remaining
after processing each step in order.
Query Languages
● XQuery is a query language under
development by the World Wide Web
Consortium (W3C). The ambitious task is to
develop the first world standard for querying
Web documents.
● XQuery is a versatile markup language,
capable of labeling the information content of
diverse data sources including structured and
semi-structured documents, relational
databases, and object repositories.
Middleware: MySQL 5.1
● Middleware: Software you call from your
application to transfer data between XML
documents and databases. For data-centric
applications.
● MySQL has an option for using XML as their
output format. In its Beta release of MySQL
5.1, several features have been added
including new XML functions.
XML Functions
MySQL version 5.1 has functions for searching
and changing XML documents:
ExtractValue() and UpdateXML().
XML Functions
xml document name
EXTRACTVALUE ( );
This function takes 2 string arguments:
The first parameter correspond to the
XML_document string, and
the 2nd Parameter XPath_string (XPath
expression / locator).
This will result in the return of the string
containing a value from the document.
EXTRACTVALUE (XML_document,
XPath_string);
EXTRACTVALUE (XML_document,
XPath_string);
UPDATEXML ( );
This function takes 3 string arguments:
The first two paramaters are similar to the ones
used with extractValue(), XML_document and
XPath_string.
The third parameter is the new value that will
replace the one found.
UPDATEXML (XML_document,
XPath_string, new_value);
Exercise
Using MySQL 5.1, create a “Movies” table, execute
a query that would retrieve a specific movie title
and another that would update a movie length.
You will send to Dr. Watson a screenshot of each
query (with select statement) along with the
folder of the database used (in MySQL\data).
It will contain the table Movie with the updated row