It3031 L04 XMLDB
It3031 L04 XMLDB
Data-Driven
Introduction to XML
Applications XML Document, XML Schema
XML data storage
XML Databases Native XML Databases
XML data type
XML enable Databases
XML data retrieve
XPath
XQuery
FLWOR
1 2
XML
Example: XML Document
XML = eXtensible Markup Language.
…
While HTML uses tags for formatting (e.g., <catalog>
“italic”), XML uses tags for semantics (e.g., “this <product dept="WMN">
is an address”). <number>557</number>
<name language="en">Fleece Pullover</name>
Key idea: create tag sets for a domain, and
translate all data into properly tagged XML <colorChoices>navy black</colorChoices>
documents. </product>
<product dept="ACC">
3 … 4
Start the document with a declaration, Tags, as in HTML, are normally matched
surrounded by <?xml … ?> . pairs, as <FOO> … </FOO> .
5 6
1
Example: Well-Formed XML Example
XML is de-facto standard for exchanging data Native XML databases (Eg: Timber, Tamino, Xindice)
stores and retrieves XML data in its native form
contain new techniques for storage and retrieval
Storing and accessing large XML data stores XML-enabled databases (Eg: Oracle, MS SQL
Server,DB2)
is gaining in importance Use existing database technology to store XML data
Database technology has matured over the last three decades
Advantage: Use more powerful existing database
technologies
Both approaches have merit!
Schema is static (structured) XML enabled DB approach is
advantageous
Schema is not static (unstructured/semi-structured) Native
11 XML DB approach is advantageous 12
2
Native storage as XML data
XML enabled approach type
Native storage as XML data type
XML storage options
XMLType data type - Oracle
Mapping between XML and existing data R. Murthy and S. Banerjee, “XML Schemas in Oracle XML DB”, VLDB,
2003.
models supported by DBMSs
Xml Type - SQL Server 2005
S. Pal, I. Cseri, O. Seeliger, G. Schaller, L. Giakoumakis and V. Zolotov,
“Indexing XML Data Stored in a Relational Database”, VLDB, 2004.
Large object storage (CLOB, BLOB)
Internal representation of stored data is preserve the
XML content of the data, such as containment
hierarchy, document order, element and attribute
values, and so on
Untyped and typed XML data Untyped and typed XML data
type type
XML values can be stored natively in an XML data type
column, which can be typed according to a collection of For MS SQL Server,
XML schemas, or can be left untyped
Untyped XML Column in Table:
Use untyped XML data type under the following CREATE TABLE AdminDocs (
conditions: id int primary key,
You do not have a schema for your XML data xDoc XML not null
You have schemas but you do not want the server to ) Schema collection
validate the data
Typed XML Column in Table:
Use typed XML data type under the following conditions: CREATE TABLE AdminDocs (
You have schemas for your XML data and you want the id int primary key,
server to validate your XML data according on the XML
xDoc XML (CONTENT myCollection)
schemas
15 ) 16
You want to take advantage of storage and query
optimizations based on type information
17 18
3
Path Descriptors
Path Expressions
XPath is a language for describing paths in Simple path descriptors are sequences of
XML documents. tags separated by slashes (/).
i.e. Xpath 1.0 and Xpath 2.0 If the descriptor begins with /, then the path
starts at the root and has those tags, in order.
Really think of the semistructured data graph If the descriptor begins with //, then the path
and its paths. can start anywhere.
19 20
4
Example: /BARS/* Attributes
5
More Axes Predicates
Some other useful axes are:
A condition inside […] may follow a tag.
parent:: = parent(s) of the current node(s).
descendant-or-self:: = the current node(s)
If so, then only paths that have that tag and
and all descendants. also satisfy the condition are included in the
Note: // is really shorthand for this axis. result of a path expression.
ancestor::, ancestor-or-self, etc.
the default axis is child:: --- go to all the
children of the current set of nodes.
31 32
35 36
6
Using Position in Predicates Using Position in Predicates
• Can use a number in the predicate to indicate the • More than one predicate can be used to
position of the child
specify multiple constraints in a step
- evaluated left to right
37 38
XQuery
39 40
XQuery Comments
41 42
7
Clauses of a FLWOR Expression for Clauses
43 44
45 46
47 48
8
Multiple for and let clauses where clause
49 50
51 52
53 54
9
Value vs. General
Comparisons
Comparisons
General Comparisons
55 56
57 58
59 60
10
Built in Functions: A Sample More built in functions
61 62
63 64
65 66
11