PART IV
Chapter 30 Semistructured Data and XML
30.1 Despite the excitement surrounding XML, it is important to note that most operational
business data, even for new Web-based applications, continues to be stored in relational
DBMSs. This is unlikely to change in the foreseeable future because of their reliability,
scalability, tools, and performance. Consequently, if XML is to fulfil its potential, some
mechanism is required to publish relational data in the form of XML documents. The
SQL:2003 standard has defined extensions to SQL to enable the publication of XML,
commonly referred to as SQL/XML. Discuss in detail these extensions.
SQL/XML contains:
a new native XML data type, XML, which allows XML documents to be treated as
a set of operators for the type:
XMLELEMENT, to generate an XML value with a single element as a child of
an implicit set of mappings from relational data to XML. The mapping may take as its
30.2 Provide XQuery expressions for the following queries based on the sample XML file (books.xml)
below.
PART IV
<price>99.00</price>
</book>
</book>
<title>Data on the Web</title>
</book>
1995
</book>
</bib>
(a) List the title of the first book.
(b) List the titles of all the books along with a count of the number of books.
PART IV
<title>Database Systems</title>
(c) List the title and price of each book published in the year 2003.
(d) List the title and numbers of authors of each book.
This produces:
<book>
</book>
<book>
(e) List the titles of books whose price is less than $60.
(f) List the titles of books in alphabetical order.
for $t //title
This produces:
(g) List the authors, sorted in reverse order of surname, then first name.
This produces:
<author>
</author>
<author>
</author>
<author>
<last>Begg</last>
(h) List the authors as a single string, sorted in reverse order of surname, then first name.
for $a in distinct-values( //author)
order by $a/last descending, $a/first descending
PART IV
(I) List the titles of books that have at least one author called Thomas Connolly.
(j) List the titles of books that have every author called Thomas Connolly.
for $b i //book
This query uses the XQuery universal qualifier, which tests whether every node in a sequence
satisfies a condition. This produces:
(k) List books by author.
<authors>
PART IV
for $l in distinct-values($a/last), $f in distinct-values($a[last=$l]/first)
}
</authors>
This produces:
<authors>
<author>
</author>
<author>
</author>
<author>
(l) Test whether the most expensive book is also the book with the largest number of
authors/editors.
PART IV
let $aCount :=
(m) List the books where Begg is an author but is not listed as the first author.
(n) List the titles of books that are more expensive than the average book price.
30.3 State the underlying type of the following expressions:
(a)
(i) 3.6e1 + 69
Databas – Part V
(a) xs:string
(b) xs:integer
30.4 State the underlying type of the following expressions:
(a) let $a := 1 + 2 return $a + $a
(b) let $a := 1e0 + 1.0 return $a + $a
(d) xs:integer (1 + 2 has type xs:integer, so variable $a has type xs:integer and return expression is also