Docsity

AN XML Query Language - Lecture Slides | CS 4440, Study notes of Computer Science

Toggle sidebar
bg1
1
XQuery: An XML Query Language
Samuel R. Collins
Ph.D. Student
College of Computing
Database Systems
Advisors:
Leo Mark
Sham Navathe
Extensible Markup Language (XML)
lXML is a simple, very flexible text format
derived from SGML
lDesigned for ease of implementation and
for interoperability with both SGML and
HTML
lOriginally designed to meet the challenges
of large-scale electronic publishing
lQuickly became the standard for data
exchange on the Web
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download AN XML Query Language - Lecture Slides | CS 4440 and more Study notes Computer Science in PDF only on Docsity!

XQuery: An XML Query Language

Samuel R. Collins

Ph.D. Student

College of Computing

Database Systems

Advisors:

Leo Mark

Sham Navathe

Extensible Markup Language (XML)

l XML is a simple, very flexible text format

derived from SGML

l Designed for ease of implementation and

for interoperability with both SGML and

HTML

l Originally designed to meet the challenges

of large-scale electronic publishing

l Quickly became the standard for data

exchange on the Web

Extensible Markup Language (XML)

l XML is capable of labeling the

information content of diverse data sources

– Structured and semi-structured documents

– Relational databases

– Object repositories

Goal

l As increasing amounts of information are

stored, exchanged, and presented using

XML, the ability to intelligently query

XML data sources becomes increasingly

important.

l The goal is to give a brief introduction to

XQuery, an XML query language.

What is XQuery?

l A functional language

l A strongly typed language

l Basic building block is the expression

l Case sensitive – Keywords use lower-case

characters

Usage Scenarios

l How XML queries may be used in various

environments

– Human-readable documents: Perform queries

on structured documents and collections of

documents (ex. technical manuals)

– Data-oriented documents: Perform queries on

the XML representation of database data,

object data, or other traditional data sources

Usage Scenarios

– Filtering Streams: Perform queries on streams

of XML data

– Document Object Model: Perform queries on

DOM structures to return sets of nodes that

meet the specified criteria

– Native XML repositories and web servers:

Perform queries on collections of documents

managed by native XML repositories or web

servers

XQuery Language

l FLWR Language

– FOR: binds and iterates over variables

– LET: binds variables

– WHERE: filters by means of predicates

– RETURN: construct results

l XPath Expression

– To address portions of a document

Sample Data: http://www.bn.com/bib.xml

TCP/IP Illustrated StevensW. Addison-Wesley 65.95

Advanced Programming in the Unix environment StevensW. Addison-Wesley 65.95

Data on the Web AbiteboulSerge BunemanPeter SuciuDan Morgan Kaufmann Publishers 39.95

The Economics of Technology and Content for Digital TV GerbargDarcy CITI Kluwer Academic Publishers 129.95

Sample Data:

http://www.amazon.com/reviews.xml

Data on the Web
34.95
A very good discussion of semi-structured database
systems and XML.
Advanced Programming in the Unix environment
65.95
A clear and detailed discussion of UNIX programming.
TCP/IP Illustrated
65.95
One of the best books on TCP/IP.

Example Query 1

l List books published by Addison-Wesley after 1991,

including their year and title.

{

for $b in document("http://www.bn.com")/bib/book

where $b/publisher = "Addison-Wesley" and $b/@year > 1991

return

{ $b/title }

}

Example Query 1 - Result

l List books published by Addison-Wesley after 1991,

including their year and title.

TCP/IP Illustrated

Advanced Programming in the Unix</p> <p>environment

Example Query 3

l For each book in the bibliography, list the title and

authors, grouped inside a "result" element.

{

for $b in document("http://www.bn.com")/bib/book

return

{ $b/title }

{ $b/author }

}

Example Query 3 - Result

Advanced Programming in the Unix environment Stevens W. Data on the Web Abiteboul Serge Buneman Peter Suciu Dan

Example Query 4

l For each author in the bibliography, list the author’s name and the titles of all books by that author, grouped inside a "result" element.

{ for $a in distinct-values(document("http://www.bn.com")//author)

return

{ $a }

{ for $b in document("http://www.bn.com")/bib/book

where some $ba in $b/author satisfies deep-equal($ba,$a)

return $b/title }

}

Example Query 4 -Result

Stevens W. TCP/IP Illustrated Advanced Programming in the Unix environment Abiteboul Serge Data on the Web Buneman Peter Data on the Web Suciu Dan Data on the Web

Example Query 6

l For each book that has at least one author, list the title and first two authors, and an empty "et-al"
element if the book has additional authors.
for $b in document("www.bn.com/bib.xml")//book
where count($b/author) > 0
return
{ $b/title }
for $a in $b/author[position()<=2]
return $a
if (count($b/author) > 2)
then <et-al/>
else ()

Example Query 7

l List the titles and years of all books published by

Addison-Wesley after 1991, in alphabetic order.

{

for $b in document("www.bn.com/bib.xml")//book

where $b/publisher = "Addison-Wesley" and $b/@year > 1991 return

{ $b/@year } { $b/title }

sort by (title) }

Example Query 8

l In the document "books.xml", find all section or chapter

titles that contain the word "XML", regardless of the

level of nesting.

{

for $t in document("books.xml")//(chapter | section)/title

where contains($t/text(), "XML")

return $t

}

Any Questions?