XML_DB - Sandre

publicité
XML et
bases de données
Pierre LAGARDE
Formation SANDRE
1
Données versus Documents
2
Documents centrés données / XML structuré
Utilisé pour les échanges de données
Construit pour l’analyse par l’ordinateur
Caractéristiques :
–
–
–
–
Structures régulières
Données faible granularité
Pas de contenu mixte
L’ordre des balises n’a pas d’importance
Exemples
–
–
3
Données scientifiques
…
Exemple de fichier XML data-centric
<Prelevement>
XML-SANDRE
4
<CdPrelevementCommanditaire>06036970 - 01012004 - TEST
PES_EAU</CdPrelevementCommanditaire>
<NumeroOrdrePrelevement>1</NumeroOrdrePrelevement>
<JourPrel>01</JourPrel>
<MoisPrel>01</MoisPrel>
<AnneePrel>2004</AnneePrel>
<PrecisionDatePrel>5</PrecisionDatePrel>
<StationPrelevement>
<CdStationPrelevement
schemeAgencyID="1">06036970</CdStationPrelevement>
</StationPrelevement>
<Support>
<CdSupport>3</CdSupport>
</Support>
<Preleveur>
<Intervenant>
<CdIntervenant
schemeAgencyID="SIRET">41054531300018</CdIntervenant>
</Intervenant>
</Preleveur>
<Echantillon>
<DestinataireEchant>
<Intervenant>
<CdIntervenant
schemeAgencyID="SIRET">22260001700081</CdIntervenant>
</Intervenant>
</DestinataireEchant>
<Analyse>
<NoAna>1</NoAna>
<InsituAna>2</InsituAna>
<Parametre>
<CdParametre>1264</CdParametre>
<NomParametre>2 4 5 T</NomParametre>
</Parametre>
<FractionAnalysee>
<CdFractionAnalysee>23</CdFractionAnalysee>
</FractionAnalysee>
<Methode>
<CdMethode>386</CdMethode>
</Methode>
<UniteReference>
Document centré document/ unstructured XML
Elaboré pour la lecture “humaine”
Caractéristiques
–
–
–
–
Structures irrégulières
Données à granularité importante (un élément = le document !)
Données mixtes
L’ordre des élément est important
Souvent ne provient pas d’une base de données
Exemples
–
–
–
5
Un livre
Un document issu de Word
..
Principales solutions pour gérer du XML
XML
documents
Files system
BD XML
native
BD
Application
mapping
XML DB
XML- enabled
Middleware
XML
BD Relationnel ou object
6
Stocker et retrouver des données
7
Solutions pour les données
Mapping
XML- enabled
database
XML
documents
Middleware
XML
structures
(XML schema)
database
Database
schema
Mapper la structure XML
Utilisation d’un langage XML
Utilisation de XSLT pour transformer la
structure XML structure dans une structure
attendue par la base de données
8
Mapper les fichiers dans le schéma de la base
Le mapping concerne
–
–
–
Les éléments, attributs et textes
Ignore la structure physique (CDATA sections,
encoding,…)
Ignore les structures logiques (processing
instructions, comments, order,…)
2 approches du mapping
–
–
9
Table-Based mapping
Object-relational mapping
Un ”import et un
export” ne crée pas le
même fichier (mais
les mêmes données)
Table-based mapping
Transférer les données dans les tables
relationnelles
<Parametre>
<CdParametre>1340</CdParametre>
<NomParametre>Nitrates</NomParametre>
<StParametre>Validé</StParametre>
<DateCreationParametre>1987-06-01</DateCreationParametre>
<DateMajParametre>2004-12-20T00:00:00</DateMajParametre>
<AuteurParametre>DIREN de bassin ILE-de-FRANCE et CENTRE
</AuteurParametre>
<LbCourtParametre>NO3-</LbCourtParametre>
<LbLongParametre>Nitrates</LbLongParametre>
<MethodeAnalyse>
<CdMethode>24</CdMethode>
<NomMethode>Essais des eaux –
Dosage colorimétrique des ions nitrate
NF T 90-012 - Février 1952)</NomMethode>
</MethodeAnalyse>
<MethodeAnalyse>
<CdMethode>25</CdMethode>
<NomMethode>Essais des eaux - Dosage des nitrates
(NF T 90-012 - Août 1975)</NomMethode>
</MethodeAnalyse>
</Parametre>
10
Parameter
Methods
Table-based mapping avec Oracle
En deux opérations
La structure
XML
XSLT
<database>
<table>
<row>
<column1>...</column1>
<column2>...</column2>
...
</row>
<row>
...
</row>
...
</table>
<table>
...
</table>
...
</database>
Java OracleXML getXML –conn “jdbc:oracle:thin@localhost:1521:orcl” –user “system/admin” “select * from parametres”
11
OracleXML
(XSU)
Demonstration with Oracle
Need Oracle 8i, 9i or 10g
Creates (or exists) a specific schema
(relational)
To show XML documents : Java OracleXML getXML –user “system/admin”
“select * from parametres”
To put XML Documents : Java OracleXML putXML –user “system/admin” -
fileName “nvpara.xml” “parametres”
12
Object-Relational mapping
Modélisation des données comme des
arbres d’objets
<<complexType>>
PARAMETRE : 1
<Parametre>
<CdParametre>1340</CdParametre>
<NomParametre>Nitrates</NomParametre>
<StParametre>Validé</StParametre>
<DateCreationParametre>1987-06-01</DateCreationParametre>
<DateMajParametre>2004-12-20T00:00:00</DateMajParametre>
<AuteurParametre>DIREN de bassin ILE-de-FRANCE et CENTRE
</AuteurParametre>
<LbCourtParametre>NO3-</LbCourtParametre>
<LbLongParametre>Nitrates</LbLongParametre>
<MethodeAnalyse>
<CdMethode>24</CdMethode>
<NomMethode>Essais des eaux –
Dosage colorimétrique des ions nitrate
NF T 90-012 - Février 1952)</NomMethode>
</MethodeAnalyse>
<MethodeAnalyse>
<CdMethode>25</CdMethode>
<NomMethode>Essais des eaux - Dosage des nitrates
(NF T 90-012 - Août 1975)</NomMethode>
</MethodeAnalyse>
</Parametre>
XML
document
13
+
+
+
+
+
+
+
+
+
+
+
+
+
Code du paramètre
Nom du paramètre
Statut du paramètre
Date de création du paramètre
Date de la dernière mise-à-jour du paramètre
Auteur du paramètre
Libellé court du paramètre
Libellé long du paramètre
Définition du paramètre
Références bibliographiques sur le paramètre
Commentaires sur le paramètre
Nom international du paramètre
Paramètre calculé
0..*
:
:
:
:
:
:
:
:
:
:
:
:
:
IdentifierType
TextType
TextType
DateType
DateTimeType
TextType
TextType
TextType
TextType
TextType
TextType
TextType
CodeType
0..*
MethodeAnalyse
<<complexType>>
METHODE : 4
+
+
+
+
+
+
+
+
+
+
XML
data
binding
Code de la méthode
: IdentifierType
Nom de la méthode
: TextType
Statut de la méthode
: TextType
Date de création de la méthode
: DateType
Date de la dernière mise-à-jour de la méthode : DateTimeType
Auteur de la méthode
: TextType
Références de la méthode
: TextType
Commentaires sur la méthode
: TextType
Libellé long de la méthode
: TextType
Nom international de la méthode
: TextType
Objects
view
Database
Object/
relational
Object-Relational mapping dans Oracle
2 solutions
–
–
Use Object view
XMLType
Demonstration of object view
Demonstration of XMLTYPE… a native XML
in Oracle ?
Very complex to create…
14
Les langages de requêtes
Permettre d’extraire des données XML d’une base
de données
Parameter
Methods
Trois approches :
–
–
–
15
Un développement spécifique
Un langage SQL amélioré
Un langage XML Query
<Parametre>
<CdParametre>1340</CdParametre>
<NomParametre>Nitrates</NomParametre>
<StParametre>Validé</StParametre>
<DateCreationParametre>1987-06-01</DateCreationParametre>
<DateMajParametre>2004-12-20T00:00:00</DateMajParametre>
<AuteurParametre>DIREN de bassin ILE-de-FRANCE et CENTRE
</AuteurParametre>
<LbCourtParametre>NO3-</LbCourtParametre>
<LbLongParametre>Nitrates</LbLongParametre>
<MethodeAnalyse>
<CdMethode>24</CdMethode>
<NomMethode>Essais des eaux –
Dosage colorimétrique des ions nitrate
NF T 90-012 - Février 1952)</NomMethode>
</MethodeAnalyse>
<MethodeAnalyse>
<CdMethode>25</CdMethode>
<NomMethode>Essais des eaux - Dosage des nitrates
(NF T 90-012 - Août 1975)</NomMethode>
</MethodeAnalyse>
</Parametre>
Un langage SQL amélioré
Utilisé le SQL avec de nouvelles commandes
SQL / XML : une évolution de ANSI/ISO SQL 2003
Exemple :
16
–
select XMLElement("Code",code_parametre) from parametres
–
Select
XMLElement("Parametre",XMLElement("CodeParametre",XM
LAttributes('SANDRE' as
"schemeAgency"),code_parametre),XMLElement("NomParam
etre",nom_parametre)) from parametres
Langage XML Query
Un langage de programmation pour
interroger des collections de données XML
XQuery
–
–
–
–
17
Développé par W3C (Working Draft in 2005)
Utilisation XPATH
Sources multiples
Spécifique à XML
Principes XQUERY
FLWR Expressions
For …. Let ….Where …Return ….
Exemples
–
–
–
18
let $a := input()/SI_DC return <p>Actually, there are
{ count($a) } networks.</p>
for $a in input()/SI_DC/Bdd where
$a/TypeBdd/CdTypeBanque = '3‘ return $a
for $a in input()/SI_DC/Bdd, $b in input()//BddRdd
where $b/Bdd/CdBdd=$a/CdBdd return
<Bdd>{$b/Bdd/CdBdd}{$a/LbBdd}</Bdd>
Principes XQUERY
Tri
Fonctions d’update
–
–
update replace
input()/SI_DC/DispositifCollecte/MnRdd[.="RBESO
UQAP"] with <MnRdd>test</MnRdd>
for $a in input()//DispositifCollecte return $a/MnRdd
Recherche de texte
19
Stocker et retrouver des
documents
20
Principals solutions to store XML documents
XML
documents
Files system
Native XML
database
XML- enabled
database
Application
mapping
XML
Middleware
Relational database
object-oriented database
21
XML DB
Stockage Files system
Très simple
Outils comme grep pour accéder XML
Pas très performant
22
Stocker les fichiers dans un BLOB
XML
documents
XML documents
(no structured)
BINARY
Database
schema
Mapper les documents XML dans un champ
binaire : BLOB
Utilisation des technologies full-text
23
Utilisation des BLOBs
Avantages
–
–
–
–
transactionnel
Sécurité
multiutilisateur
Administration
Quelques produits sont are XML-aware
–
–
Elimine le problème des tags
Compatible avec le langage XQUERY
Oracle 9i+
Db2
24
Utilisation d’une base native XML
XML
documents
XML documents
(no structured)
XML native
database
Une base de données optimisée pour le
stockage XML
Utilise uniquement des XML technologies :
XPath, XQuery,…
25
Définition d’une base de données XML native
Un terme marketing de Tamino et non une
définition technique.
Définition
–
–
–
26
Un modèle logique pour des documents XML
XML document = l’unité de base du stockage (= une
ligne en BD relationnel)
Pas de modèle particulier pour le stockage physique
Native XML Database Architecture
Text-Based Native XML Database
–
–
–
–
–
Store XML as text
File system, BLOB, …
Indexes of all text
Speed advantage when retrieving entire documents
Slow to find pieces of many documents
Similar to a
hierarchical database
Model-Based Native XML Database
–
–
–
27
Store XML documents in an internal object model
Performance similar to text-based
Less slower to find pieces of many documents
Features of Native XML Databases
Document Collections
–
–
Notion of collection (=table in an relational database)
Hierarchy of collections like directories in an file
system
Query Languages
–
–
Support one or more query languages
XPath, XQuery,…
Transactions, Locking and Concurrency
–
–
–
28
Support transactions
Locking at the level of entire documents
In the future, locking at the level of elements,…
Features of Native XML Databases
Application Programming Interface : API
–
–
–
–
Offer programmatic APIs
Proprietary APIs
XQuery for Java
Most XML Databases offer the ability to execute
HTTP queries
Round-tripping
–
Store an XML document and get the “same”
document back again
Remote data / repository
–
29
Some database include remote data and repository
Features of native XML Databases
Indexes
–
–
–
A way to increase query speed
Structural indexes
Full-text indexes
External entity storage
–
30
The problem to store external entities
An example : Tamino (Software AG)
A server oriented
native XML
Database
Features
–
–
–
–
31
Proprietary Modelbased storage
Storage and search
data with Query
interpreter
Based from XML
Standards
Connexion with XML
softwares
An example : Tamino (Software AG)
XML Engine
–
Native XML storage
Query processors
–
–
XQuery
X-Query (!)
XML Datamap
–
–
Metadata about XML documents
Describes where the data in a given XML
document is stored
X-Tension
–
access various external applications
Management / Security
32
Demonstration Tamino
33
An example : eXist
http://exist.sourceforge.net/
An OpenSource native XML database
Features
–
–
–
–
–
–
–
–
34
Proprietary Text-based storage (B+-trees and paged
files)
Hierarchical collections
Automatic Indexes
Supports XQuery
Full-text search
Work with HTTP / Java
Support XUpdate
No transaction support
Demonstration eXist
35
eXist : example of SANDRE
Store schemas XML published by the
SANDRE
Find markup and characteristics
Download schemas
Parse XML documents
36
An example SANDRE
Schema = an XML document
DB Schema = XML database eXist
Search and publish tags = XQuery
37
The market for XML database products
Categories of XML products
–
Middleware : Software you call from your application to transfer data
between XML documents and databases
–
–
–
XML-enabled database
Native XML database
XML Servers : XML-aware J2EE servers, Web application servers,
integration engines, and custom servers.
–
Wrappers : Software that treats XML documents as a source of relational
data. These products typically query XML documents using SQL.
–
XML Query engines : Standalone engines that can query XML
documents
–
XML Data bindings : Products that can bind XML documents to
objects. Some of these can also store/retrieve objects from the database.
38
Products : Middleware
Lot of products !
39
ADO
Microsoft
DBXML
XML DB
XML SQL Utility for
Java
Oracle
DBXML
XML DB
XSQL Servlets
Oracle
DBXML
XML DB
Castor (Java)
OpenSource
DBXML
XML DB
Alliance XML/400
(AS/400)
Patrick Townsend
DBXML
XML DB
Pear_XML (php)
Opensource
DBXML
XML DB
Products : XML-Enabled database
Main databases are XML-Enabled…
… if you buy recent versions
… with important differences in the implementation
of XML features
40
ACCESS (2000+)
Microsoft
Relational
DB2
IBM
Relational
Informix
IBM
Relational
Oracle 8i,9i, 10g
Oracle
Relational
SQL Server (2000+)
Microsoft
Relational
Sybase ASE
Sybase
Relational
Products : Native XML database
Lot of opensource implementations…
Commercial ?
41
Tamino
Sofware AG
Proprietary model
Sonic XML Server
Sonic software
Object-oriented
dbXML
OpenSource
Proprietary model
eXist
OpenSource
Text model
Berkeley DB XML
OpenSource
Key-value
ozone
OpenSource
Object-oriented
XIndice (Apache)
OpenSource
Proprietary (Model-based)
Products : others
XML Servers
–
–
–
Cocoon (Apache)
ColdFusion
(Macromedia)
Zope (OpenSource)
Data bindings
–
–
–
–
XQuery engine
–
–
–
–
–
–
42
BQ-XQuery engine
Web Logic Integration
XQuery engine
DataDirect XQuery™
XQEngine
XQuery for .NET
XQuery Processor
–
Castor
JAXB for Java
Jakarta (Apache)
XDK Oracle
XML definition tool
(.net)
Wrappers
–
–
SQLServer
DB2 Information
Integrator
Advantages / Disadvantages of relational database
Very used !
Rules to organise data
(modelling data) and
manages the RDMS
Complex (and slow) to
find hierarchical data
(with join,…)
Bad performance with
document
Efficient with data
Allow all types of
search
SQL standard
43
Need engine to
generate and
understand XML
documents
Advantages / Disadvantages of XML-Enabled database
A database to store
relational AND XML
documents
Rules to organise data
(modelling data) and
manages the DDMS
Efficient with data and to
mapping XML Data
SQL extension  less new
skills to be acquired
44
Complex to manage
Data type conversion
and Null data
Binary data ?
Character Sets
Advantages / Disadvantages of native XML database
All is made to manage
XML documents
Efficient to store and
use XML documents
Performance to find an
document or an
fraction of document
XQuery / XPath
45
No mandatory
normalization
Problem of referential
Integrity
Less good
performances when
you search pieces of
documents
Scability
Tools to develop
applications
Others types of data ?
New skills
Comparison relational, XML-enabled, Native
yours needs
Relational DB
XML-Enabled DB
Native XML DB
Database to store
very structured
data. Complex and
different queries /
analysis,…
Lot of data
The best solution
Allow to answer all
queries with the
good average
performance
Why not ?
To allow to
exchange with XML
formats
?
Database to store
XML documents.
Always the
equivalent queries
XML documents = a
binary information
Not optimized
A good solution
allowing to use the
same database
The best solution.
A “classical”
solution. Need
import / export
interface
A good solution
A good solution.
Allow to have
quickly a database
Database to store
structured data. Lot
of import / export in
XML exchanges.
46
Database to store
structured data and
to publish
information (HTML,
PDF,
WebServices,…)
A “classical”
The best solution.
solution but need to
Store in relational
develop tools to
database but allows
publish information
the push of XML
Documents and
transformation
Why not if you
succeed in
organizing your
data
Links about XML Databases
XML family : www.w3c.org
Introduction to native XML database :
http://www.xml.com/pub/a/2001/10/31/nativexmldb.html
History of XML database :
http://www.eaijournal.com/PDF/XMLMcGoveran.pdf
XQuery : http://www.xml.com/pub/a/2002/10/16/xquery.html
Oracle : http://www.oracle.com/technology/tech/xml/index.html
Tamino :
http://www1.softwareag.com/Corporate/products/tamino/default.asp
XIndice : http://xml.apache.org/xindice/
eXist : http://exist.sourceforge.net/
SANDRE : www.sandre.eaufrance.fr
XML-EAU :
http://www.sandre.eaufrance.fr/francais/frame/sagen.htm?page=.
./../xmleau/index.html
47
Téléchargement