Escolar Documentos
Profissional Documentos
Cultura Documentos
XPath
XQuery
Joins, aggregation
Transform XML values from one schema to another
XML construction
QSX (LN 3)
Query Languages
XPath
</book>
<book year=2003>
QSX (LN 3)
QSX (LN 3)
DTD
Data model
Node-labeled, ordered tree
<!ELEMENT
bib
(book*) >
<!ELEMENT
book
bib
book
<!ELEMENT
year
CDATA
<!ELEMENT
editor
<!ELEMENT
#required >
book
book
.
last
QSX (LN 3)
first
last
last
first
QSX (LN 3)
first
6
XPath
XPath constructs
XPath query Q:
//author[last=Bush]
//book[author/last=Bush]/title | //book[author/last=Blair]/title
bib
book
last
first
last
first
Downward traversal
QSX (LN 3)
first
Examples:
parent/child: /bib/book
Syntax:
Q ::= . |
q ::= Q |
| @l
Q op c
| Q/Q
Q|Q
| q and q
| //Q
| /Q
q or q
Q[q]
| not(q)
bib/book/*
attributes:
bib/book/@year
@l: attribute
bib
book
book
c: constant
title author author publisher phone @year
QSX (LN 3)
last
last
first
Filters (qualifiers)
10
last
first
first
Upward traversal
Syntax:
//book[price]/title
Q ::=
| ../Q
| ancestor ::Q
ancestor-or-self::Q
../: parent
1991
Example:
//author[../title = WMD]/last
//book[author/last = Bush]/title
find the last names of authors of books with the title WMD
ancestor :: book[//last=Bush]
//book[author or editor]/title
Existential semantics:
What is /[//@id]?
...
/[//[not(@id)]]?
../book/author,
/[not(//[not(@id))]] ?
QSX (LN 3)
11
./author
QSX (LN 3)
12
Sideways
Syntax:
Q ::=
...
following-sibling ::Q
XPath
preceding-sibling::Q
XQuery
XSLT
Example:
following-sibling :: book [//last=Bush]
find the books that are right siblings and are written by Bush
preceding-sibling :: book[//last=Bush]
find the books that are left siblings and are written by Bush
QSX (LN 3)
13
QSX (LN 3)
XQuery
FLWR Expressions
Q1: Find titles and authors of all books published by AddisonWesley after 1991.
XQuery = XPath +
<book>
<title> {$book/title } </title>,
for $author in $book/author return
<author> {$author } </author>
+ Strong typing
Enforced statically or dynamically
</book>
}</answer>
http://www-db.research.bell-labs.com/galax/
http://www.saxonica.com QSX (LN 3)
<answer>{
for $book in /bib/book
QSX (LN 3)
join
<answer>{
<answer>{
$bn := doc(http://www.BN.com/books.xml)
return <book>
$a in $amozon/books/book,
$b in $bn/books/book
where
$a/isbn = $b/isbn
and
16
Conditional expression
for
14
{ if $book[price]
else ( ) }
}</answer>
</book>
let clause
}</answer>
17
QSX (LN 3)
18
19