Tải bản đầy đủ (.pdf) (32 trang)

Tài liệu Module 8: Using XQuery to Link and Query XML Documents ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (887.65 KB, 32 trang )

Module 8: Using
XQuery to Link and
Query XML Documents
Contents
Overview
Lesson: What Is XQuery?
Lesson: Using XQuery

1
2
11

Lab 8: Using Simple and Advanced
XQuery Expressions

17

Review

22

Course Evaluation

23


Information in this document, including URL and other Internet Web site references, is subject to
change without notice. Unless otherwise noted, the example companies, organizations, products,
domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious,
and no association with any real company, organization, product, domain name, e-mail address,
logo, person, places or events is intended or should be inferred. Complying with all applicable


copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part
of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted
in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or
for any purpose, without the express written permission of Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.
 2001 Microsoft Corporation. All rights reserved.
Microsoft, MS-DOS, Windows, Windows NT, ActiveX, BackOffice, bCentral, BizTalk,
FrontPage, MSDN, MSN, Netshow, PowerPoint, SharePoint, Visio, Visual Basic, Visual C++,
Visual C#, Visual InterDev, Visual Studio, Windows Media, and Xbox are either registered
trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.
The names of actual companies and products mentioned herein may be the trademarks of their
respective owners.


Module 8: Using XQuery to Link and Query XML Documents

iii

Instructor Notes
Presentation:
50 Minutes
Lab:
20 Minutes

This module is designed to provide participants with an introduction to the core
concepts of XQuery and to familiarize them with the structure of XQuery
expressions.

XQuery can be a challenging topic to teach. There is only enough time to cover
what it is, what it can do, and its basic syntax, but not in any depth. This
module leaves the detailed coverage of XQuery for later courses. Just as Course
1913A, Exchanging and Transforming Data Using XML and XSLT, is a fiveday course on Extensible Stylesheet Language Transformations (XSLT), it is
possible to devote a full five-day course to XQuery after it is fully specified and
achieves W3C Recommendation status.
Stress that XQuery is still in development by the World Wide Web Consortium
(W3C) and is not yet finalized. Participants may ask why the module is
included, considering the state of development of XQuery. It is included,
because XQuery is expected to be a W3C Recommendation by the end of 2001
and heavily used in the Internet and environments like Microsoft® .NET when it
is a stable Recommendation.
XQuery is important, because to effectively do data-centric work on the
Internet, you need to have XQuery or its equivalent. Without such a language
and set of capabilities, the use of XML is severely limited. Because XML is
fundamentally about representing data and metadata, XQuery is essential.
After completing this module, participants will be able to:
!

Understand the key concepts behind XQuery.

!

Design simple and advanced XQuery expressions.

!

Identify solutions where XQuery is the suitable technology.

!


Describe how you might apply XQuery expressions to query an XML
document.

!

Relate XQuery to the broader Microsoft .NET Framework and strategy.


iv

Module 8: Using XQuery to Link and Query XML Documents

Materials and Preparation
Required Materials

To teach this module, you need the following materials:
!

Microsoft PowerPoint® file 2500A_08.ppt

!

Access to the Microsoft MSDN® XQuery demonstration site at
http://131.107.228.20/xquerydemo/

!

Access to the W3C XQuery site at />Download and read the most recent W3C and MSDN Online documentation
on XQuery.


Preparation Tasks

To prepare for this module:
!

Read all of the materials for this module.

!

Complete the lab.

!

Deliver the demonstration that uses the XQuery demonstration site.
This site is likely to be modified from time to time to reflect W3C progress
and developments, so check it regularly so that you are not surprised by
changes. It is best to review it before each class.

!

Review as many XQuery use cases as you can to consolidate your
understanding of XQuery.

!

Work out additional examples of where XQuery can be used in your
location and with your clients.



Module 8: Using XQuery to Link and Query XML Documents

v

Instructor Setup for the Lab
For this lab, the instructor computer and all student computers must be
connected to the Internet. The lab enables participants to use the MSDN
XQuery demonstration site to gain more familiarity with the capabilities of
XQuery. Become thoroughly familiar with the demonstration site and be
prepared to answer questions.
Lab 8: Using Simple and
Advanced XQuery
Expressions

! Prepare for the lab
1. Download and review the data files from the XQuery demonstration site.
These are for ease of reference only.
2. Review the lab steps and be prepared to explain the XQuery syntax if
required. Participants are likely to find some of the queries, particularly the
advanced queries, somewhat confusing.

Demonstration
There are only two demonstrations in this module. The first demonstration
gives a quick example of how easy it is to do an SQL query with a good
graphical tool. The discussion point of the demonstration is to contrast this with
the tedious coding that would be required for XQuery without such tools.
You may want to keep this demonstration short or you may want to discuss it in
some detail, depending on the backgrounds of the participants. Be sure to point
out that at present there is no comparable graphical tool for use with XQuery.
Graphical Queries in

SQL and Access

! Prepare for the demonstration
1. Be sure that you are familiar with building queries with both the Microsoft
SQL Server™ and Microsoft Access graphical interfaces.
2. For the demonstration of the graphical interface in SQL Server, complete
the following steps:
a. Open Microsoft SQL Server Enterprise Manager.
b. Expand the pubs database under Databases.
c. Under the pubs database, click Tables.
d. Right-click the publishers table, point to Open Table, and then
click Query.
e. Click the Add table toolbar button, and then add the titles, titleauthor,
and authors tables.
f. Choose the following columns: pub_name, title, price, au_lname, and
au_fname. Remove the * from the SELECT statement so that you only
have the indicated columns listed in the SELECT statement.
g. Run the query by clicking the Run icon.
h. In the criteria cell for pub_name, type New Moon Books and then rerun
the query.


vi

Module 8: Using XQuery to Link and Query XML Documents

3. (Optional) If you have time, repeat the demonstration, this time using
Access.
a. Using Access, open the pubs.mdb file located in the install_folder\
Democode\Mod08 folder.

b. Maximize the Access window and the database container window.
c. In the database objects list, click Tables and then click the publishers
table.
d. On the toolbar, click New Object, and then click Query.
e. Choose Design View from the list.
f. On the toolbar, click Show Table to add the titles, titleauthor, and
authors tables.
The tables show the relationship links that have been defined between
the primary and foreign keys.
g. Drag the pub_name, title, price, au_lname, and au_fname columns
from the tables into the first row of the query grid, and then click the
Run icon.
h. Show that you get the same results as you did when you used
SQL Server.
i. Switch back to Design view, and in the criteria cell for pub_name, type
New Moon Books.
j. Rerun the query.
k. Now select the SQL View of the query, and then compare it with the
SQL query.
The second demonstration introduces the participants to the MSDN XQuery
language demonstration site so that they will not have to spend much time
becoming familiar with it during the lab.
Using a Variety of
XQuery Methods

! Prepare for the demonstration
1. On the MSDN XQuery demonstration site, open each of the links in the left
pane and be sure that you are familiar with the topics presented there.
2. Become familiar with the behavior of the Web page.
You will need to refresh the page or use the Back button to return to the

XQuery page after you select links for background topics (for example,
Readme, Known issues). The page also refreshes when you select a sample
query.
3. Show the class the sample files that have been copied to the
install_folder\Democode\Mod08 folder.
4. Open bib.xml to show the structure of the document.
5. Under Default Cases, click Example 2, and then run the query.
You may have to scroll to see all parts of the query page.
6. Discuss the results.
7. Repeat this sequence for Example 1 and for Example 4 and walk through
each query and the results.


Module 8: Using XQuery to Link and Query XML Documents

vii

Module Strategy
The module should not take longer than the allotted time to do. Because this is
likely to be new material to most participants, emphasize that this is an
introduction to an aspect of XML technologies that is going to be very
important to XML and to Microsoft .NET. Use the following strategy to present
this module:
!

What Is XQuery?
This lesson is built around a number of questions that almost anyone who
approaches XQuery will have.
Move through the topics at a comfortable pace and stop to discuss questions
that the participants may have. Be prepared to work through the examples

and the concepts as needed.
Stress that XQuery is incomplete, as long as that remains true. When
XQuery reaches W3C Recommendation status, you will need to adjust the
presentation of the module if the course is not revised. Be sure to explain
FLWR expressions. These will be seen in the examples in the second lesson
and in the lab.
Work through each of the topic slides and discuss the central concepts and
associated ideas. The class may want to discuss some topics in more depth.
Keep an eye on the time.
Be sure that you are comfortable with the complexities of the XQuery
examples. The best way to prepare for this is to read the W3C papers
carefully and to spend adequate time with the XQuery demonstration site to
get a good idea of how these queries look and behave.

!

Using XQuery
This lesson is designed to focus attention on examples of XQuery syntax,
which you can work through in detail with the class.
Be ready to expand upon these examples with what you learned from the
W3C documents and the XQuery demonstration site. Focus on the basics
and try not to discuss the very advanced features of XQuery, because they
will likely be too difficult for newcomers to the topic.
Discuss the similarities and differences between SQL queries and XML
queries. Emphasize the differences between SQL and XML in their ability
to handle redefinition of output. Also emphasize that XML is self-defining
and self-modifying in this regard.




Module 8: Using XQuery to Link and Query XML Documents

1

Overview
!

What Is XQuery?

!

Using XQuery

*****************************ILLEGAL FOR NON-TRAINER USE******************************
Introduction

In this module, you will see why Extensible Markup Language (XML) requires
a specific query language and how XQuery fulfills this requirement.
This module is not designed to give you an exhaustive introduction to XQuery,
because there is neither time nor space for that in this course. It is designed to
provide you with an introduction to XQuery and the background of significant
developments in XQuery.
This module shows the difference between XQuery and XML Path Language
(XPath). It then shows examples of XQuery expressions and syntax with
sample XML documents to show how XQuery enables you to retrieve data in a
manner analogous to an SQL query in a relational database.

Objectives

After completing this module, you will be able to:

!

Understand the key concepts behind XQuery.

!

Design simple and advanced XQuery expressions.

!

Identify solutions where XQuery is the suitable technology.

!

Describe how you might apply XQuery expressions to query an
XML document.

!

Relate XQuery to the broader Microsoft® .NET Framework and strategy.


2

Module 8: Using XQuery to Link and Query XML Documents

Lesson: What Is XQuery?
!

Why Do You Need XQuery?


!

XQuery Expression Basics

!

XQuery and SQL

*****************************ILLEGAL FOR NON-TRAINER USE******************************
In this lesson the rationale behind the development of XQuery is explained.
You will learn how XQuery and XPath are related and how XQuery and SQL
are related. You will gain a first exposure to the query syntax of XQuery.
Lesson Objectives

After completing this lesson you will be able to:
!

Explain the relationship between XQuery and XPath.

!

Interpret the syntax of an XQuery expression.

!

Describe the uses of XQuery in relation to XPath and SQL.


Module 8: Using XQuery to Link and Query XML Documents


3

Why Do You Need XQuery?
XPath is limited:

With XQuery, you can:

!

Navigate a single XML source
at a time

!

Query multiple sources
at once

!

Query XML sources only

!

!

Run simple queries

Simultaneously query XML
sources and relational data


!

Run complex queries

XML Example

XQuery Expression

SQL Query

*****************************ILLEGAL FOR NON-TRAINER USE******************************
Introduction

Every day more data is made available formatted in XML. Still much of the
world’s data is stored in relational databases. There is a need for an efficient
query language that can extend a query across a variety of XML sources and to
relational data sources. The World Wide Web Consortium (W3C) has been
working on a specification to address this need. The specification that has
emerged has sometimes been called XML Query but is more commonly known
simply as XQuery.
Note For more information about XML Query, see the XML Query page at
/>
Limitations of XPath

XPath is inadequate to extend queries across multiple XML sources. You
cannot use XPath to query relational data. You can only use XPath to and this
has helped to drive the efforts to find a better query language. As XQuery is
developed, both the XPath and Extensible Stylesheet Language (XSL) working
groups are engaged in revisions to their respective technologies to take account

of the power and functionality of XQuery.
As currently conceived by W3C, XQuery will ultimately be able to work across
any number of data stores, including relational, structured and semistructured
documents, and object repositories.

XQuery use cases

There are numerous scenarios that require a query of XML data. Here are two
brief examples:
!

Several different business partners have sent you their catalogues in XML,
and you want to compare prices and features of like products.

!

A scientist is researching medical uses of botanicals and wants to compare
her research results with colleagues in other institutions. Research data is
stored in both XML data stores and relational databases.


4

Module 8: Using XQuery to Link and Query XML Documents

XQuery and XPath 2.0

The ideas incorporated in XQuery for powerful querying of data documents
have led to revisions of the XPath specifications. Indeed, the W3C specification
XPath version 2.0 is being developed jointly by the XPath and XQuery working

groups. When you consider the basic issues involved in navigating in XML and
querying data in XML, it is clear why the technologies are being developed
together.
XPath has limited support for data types, and it is not rich enough for querying
data. For example, you cannot use XPath for relational comparisons, sorting or
modifying XML content. In contrast, XQuery enables you to:
!

!

List all parts produced by a manufacturer and then group them by category
inside an output element.

!

XQuery Capabilities

List all parts produced by a manufacturer that have a price that is less than a
particular value.

Find all parts of the same type produced by Manufacturer A and
Manufacturer B and then produce a combined listing.

The development of XQuery will lead to the enhancement of the XPath
language after the working groups finish their work on XPath 2.0. According to
W3C, XQuery must be able to handle the following:
!

Data and data types


!

Projection

!

Iteration

!

Selection

!

Quantification

!

Joins

!

Restructuring and grouping

!

Querying order

!


Sorting

!

Aggregation

!

Expanded names

!

Functions

Note For a full listing of the requirements for XQuery, see the topic “XQuery
Semantics by Example” in the W3C document XQuery 1.0 Formal Semantics.


Module 8: Using XQuery to Link and Query XML Documents

Example

Consider a situation in which you have an XML data document named
books.xml. This document has an associated document type definition (DTD)
or XML Schema Definition (XSD). Sample data from books.xml (from the
Pubs database from Microsoft SQL Server™ 2000), located at
t, looks like this:
<books>
<book pubyear=1991>
<title>Cooking with Computers: Surreptitious Balance

Sheets</title>
Algodata Infosystems</publisher>
<familyname>MacFeather</familyname>
<givenname>Stearns</givenname>
11.95</price>
</book>
<book pubyear=1991>
<title>You Can Combat Computer Stress!</title>
New Moon Books</publisher>
<familyname>Green</familyname>
<givenname>Marjorie</givenname>
2.99</price>
</book>
<book pubyear=1991>
<title>Is Anger the Enemy?</title>
New Moon Books</publisher>
<familyname>Ringer</familyname>
<givenname>Anne</givenname>
10.95</price>
</book>
</books>

To find all books published by New Moon Books after 1990 and to list their
title and year of publication, write the following XQuery expression:
<books>
{
FOR $b IN document ("t")/books/book
WHERE $b/publisher = "New Moon Books" AND $b/@pubyear > 1990
RETURN
<book pubyear={ $b/@pubyear }>

{ $b/title }
</book>
}
</books>

5


6

Module 8: Using XQuery to Link and Query XML Documents

The following is the same query in SQL:
SELECT
FROM
WHERE

pubyear, title
books
(pubyear > 1990) AND (publisher = 'New Moon Books')?)

From the XQuery expression, you get:
<books>
<book pubyear="1991">
<title>You Can Combat Computer Stress!</title>
</book>
<title>Is Anger the Enemy?</title>
</book>
</books>


From the SQL query, you get:
pubyear

title

1991

You Can Combat Computer Stress!

1991

Is Anger the Enemy?


Module 8: Using XQuery to Link and Query XML Documents

7

XQuery Expression Basics
!

XQuery expressions use the FLWR syntax

FOR, LET, WHERE, RETURN
<books>
<books>
{
{
FOR $b IN document

FOR $b IN document
(“)/books/book
(“)/books/book
WHERE $b/publisher = "New Moon Books" AND
WHERE $b/publisher = "New Moon Books" AND
$b/@pubyear > 1990
$b/@pubyear > 1990
RETURN
RETURN
<book pubyear={ $b/@pubyear }>
<book pubyear={ $b/@pubyear }>
{ $b/title }
{ $b/title }
</book>
</book>
}
}
</books>
</books>
"

*****************************ILLEGAL FOR NON-TRAINER USE******************************
Introduction

In the same way that SQL was developed to query relational data, XQuery is
designed to query XML documents and data sources. Importantly, it is also a
relational query language that builds on the history of SQL and other
predicate-based systems and algebra. XQuery is strongly typed and a strong
predicate language. By using FLWR expressions in XQuery expressions, you
can:

!

Select data and metadata from data documents or other data stores.

!

Transform data and metadata by returning query results and manipulate the
results into a different XML tree form upon retrieval.

!

Query document fragments that do not have a root element.

!

Access and manipulate data of all types, including user-defined data types.
This presumes full support for the XSD data types specified by W3C.


8

Module 8: Using XQuery to Link and Query XML Documents

FLWR expressions

The central ideas of XQuery are analogous to SQL query concepts. FLWR
(pronounced like flower) expressions allow queries of XML data documents
and fragments of documents that are similar to SQL queries.
An XQuery expression can be a simple XPath expression, but users and
application usually require more sophisticated queries. XQuery expressions are

built upon the following four keywords. Keywords in XQuery are not
case-sensitive.
!

FOR
You use the FOR clause to iterate through data by using one or more
variables that are associated with expressions. The expressions can be path
references or other legitimate XML expressions.

!

LET
You also use the LET clause to bind variables. However, unlike the FOR
clause, it does not iterate. Therefore, it binds a variable to a single value for
the expression.

!

WHERE
The WHERE clause is similar to the WHERE clause in SQL. It filters the
data to determine which data qualifies as a result of the query.

!

RETURN
The RETURN clause is what generates the output from the FLWR
expression and can be values or a node pattern. It can be further qualified by
element constructors, sorting, calculations, or comparisons. An element
constructor is an XML element that represents itself and allows you to
generate new elements from within the query.


FLWR expressions are processed in a particular order. Any FOR or LET clause
is processed first, then, any WHERE clause is processed, and then any
RETURN clause is processed.


Module 8: Using XQuery to Link and Query XML Documents

9

XQuery and SQL
!

SQL is designed specifically for
relational environments

!

XQuery is designed to concurrently navigate and
manipulate multiple relational and XML data sources

*****************************ILLEGAL FOR NON-TRAINER USE******************************
Introduction

Querying data requires the same types of constructs regardless of the query
language or natural language. All queries are variants of the following phrases
and qualifiers:
!

Find something.


!

Find something in some location.

!

Find something with some conditions.

!

Process or group the results based on some rules.

This is precisely what XQuery does with XML documents, just as SQL does
with a relational database.
SQL vs. XQuery

With SQL, you can use advanced query environments with graphical interfaces
such as those found in Microsoft Access and SQL Server. While such tools will
certainly be produced for XQuery, they do not exist in any sophisticated form
at present.


10

Module 8: Using XQuery to Link and Query XML Documents

Demonstration: Graphical Queries in SQL and Access
!


In this demonstration you will see a query
being built in SQL Server 2000 using the
graphical query interface

!

(Optional) If time permits you will see a
similar query built in Access 2002

*****************************ILLEGAL FOR NON-TRAINER USE******************************
In the demonstration, you will see a comparison of the graphical creation of an
SQL query and a current prototype from Microsoft of a basic query interface.


Module 8: Using XQuery to Link and Query XML Documents

11

Lesson: Using XQuery
!

Basic XQuery

!

Advanced XQuery

!

The Future of XQuery


*****************************ILLEGAL FOR NON-TRAINER USE******************************
Introduction

To use XQuery, you need specific skills beyond what is required by basic
XML. In this lesson, you will learn those skills and how to write an
XQuery expression.

Lesson objectives

After completing this lesson, you will be able to:
!

Create basic queries using the XPath features of XQuery.

!

Explain and use the advanced XQuery operators.

!

Identify situations where you can use XQuery.

!

Plan and design how and where XQuery might be used in a Microsoft .NET
solution or application.


12


Module 8: Using XQuery to Link and Query XML Documents

Basic XQuery
!

Basic XPath type queries

document("animals.xml")//section
document("animals.xml")//section
[4]//illustrations
[4]//illustrations
[label = “Cat family”]
[label = “Cat family”]
document("animals.xml")//section
document("animals.xml")//section
[3 TO 7]//illustration
[3 TO 7]//illustration
document("animals.xml")//section
document("animals.xml")//section
[title =
[title =
"Cats"]//illusref/@illusid=>illus/label
"Cats"]//illusref/@illusid=>illus/label
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Introduction

In this topic, you will examine the structure of basic XQuery expressions. You
will need to take your time to examine these examples. As a newcomer to
XQuery, you might think its syntax is rather awkward.

Just as it usually takes time to get used to SQL queries for those new to
relational databases, it will take time to get used to XQuery, because it is even
less familiar. Knowledge of SQL is only a partial advantage in learning
XQuery. Some may find that SQL knowledge hinders learning XQuery.

Examples

The following are examples of types of XQuery expressions:
!

Given a document called animals.xml, find, in the fourth section, the
illustrations with the label “Cat family.”
document ("animals.xml")//section[4]//illustration[label =
"Cat family"]

!

Given the same document, find all the illustrations in sections 3 through 7.
document("animals.xml")//section[3 TO 7]//illustration

!

You can use a special XQuery operator called a dereference (represented by
=>) with documents that have an attached DTD or XSD and therefore allow
the use of the ID, IDREF, and IDREFS special node types. This enables you
to select items based on the attributes of an element.
Given the same document, use the dereference operator to find the label of
the <illus> element that is referenced by the illusid attribute of an <illusref>
element.
document("animals.xml")//section[title =

"Cats"]//illusref/@illusid=>illus/label


Module 8: Using XQuery to Link and Query XML Documents

13

Advanced XQuery
FOR $p IN
FOR $p IN
distinct(document("books.xml")//publisher
distinct(document("books.xml")//publisher
LET $a := avg(document("books.xml")
LET $a := avg(document("books.xml")
//book/[publisher = $p]/price)
//book/[publisher = $p]/price)
RETURN
RETURN


<name> {$p/text () } </name>
<name> {$p/text () } </name>
<avgprice> {$a} </avgprice>
<avgprice> {$a} </avgprice>
</publisher>
</publisher>
Transforming a Document

Alphabetical List


*****************************ILLEGAL FOR NON-TRAINER USE******************************
Introduction

Most of the interest in XQuery is due to its advanced capabilities. These include
the use of FLWR expressions to handle complex queries and manipulate query
results. You can manipulate query results by restructuring the XML so that
there are different types of nodes or nodes that are in a different order from the
source. You can also join multiple data sources in joins, sort, and perform
calculations.

Examples

In this example, a LET clause binds the variable $a to the average price of
books that are published by the publishers that are bound in the FOR clause:
FOR $p IN distinct(document("books.xml")//publisher
LET $a := avg(document("books.xml")//book/[publisher =
$p]/price)
RETURN

<name> {$p/text () ] </name>
<avgprice> {$a} </avgprice>
</publisher>


14

Module 8: Using XQuery to Link and Query XML Documents

In this example, a document is transformed so that it has a different output form
than the source document:

{
FOR $a IN distinct(document("books.xml")//author)
RETURN
<author>
<name> {$a/text()} </name>
{
FOR $b IN document("books.xml")//book[author
= $a]
RETURN $b/title
}
</author>
}
</author_list>

In this example, all books with a price greater than $80 are listed in order by the
first author name. Then, that list is put in order by title.
Document("books.xml")//book[price > 80] SORTBY (author[1],
title)

This example produces a list of publishers in alphabetical order. For each
publisher, book titles and prices are listed, with prices in descending order.

{FOR $p IN distinct(document("books.xml")//publisher)
RETURN

<name> {$p/text()} </name>
{FOR $b IN document ("books.xml")//book[publisher =
$p]
RETURN

<book>
<$b/title>
<$b/price>
</book>
SORTBY (price DESCENDING)
}
</publisher>
SORTBY(name)
}
</published_list>


Module 8: Using XQuery to Link and Query XML Documents

15

The Future of XQuery
!

The universal query language for XML and Web-based
data work

!

Opens new possibilities to query combinations of
data stores
"

XML and XML fragments in all kinds of documents


"

XML bound in relational database
management systems

*****************************ILLEGAL FOR NON-TRAINER USE******************************
Introduction

The future of XQuery depends on many factors, but you will probably see the
following patterns.

XQuery and the Internet

The overall flexibility and power of XQuery and its associated technologies
(XPath 2.0 and XSD) make XQuery the query language endorsed by W3C for
use in XML documents and environments.
In the foreseeable future, you will see XQuery as the preferred query language
for Internet-based and data-centric tasks. Tools will also be developed that
make XQuery easier to use when vendors, developers, and users work with
XQuery and discover its strengths and weaknesses.
If the full power of XQuery as conceived by W3C can be adequately and
conveniently achieved in production environments, XQuery is destined to
become the common query language for all Internet-based commerce. Because
it is self-defining and self-modifying like XML, it is ideally suited to efficient
querying over the Internet for virtually any purpose and with virtually any data
store or source. Such flexibility is highly attractive to Web and application
developers if XQuery can also query data in a robust and secure manner.


16


Module 8: Using XQuery to Link and Query XML Documents

Demonstration: Using XQuery
!

In this demonstration you will see one
implementation of XQuery ideas as
developed by Microsoft team members

!

This demonstration is illustrative only as
the specifications from the W3C are not
finalized for XQuery

!

This demonstration is web based and is
found at:
http://131.107.228.20/xquerydemo/demo.aspx

*****************************ILLEGAL FOR NON-TRAINER USE******************************


Module 8: Using XQuery to Link and Query XML Documents

17

Lab 8: Using Simple and Advanced XQuery Expressions

!

Exercise 1: Using Basic XQuery

!

If Time Permits: Exploring XQuery

*****************************ILLEGAL FOR NON-TRAINER USE******************************
Objectives

After completing this lab, you will be able to:
!

Use the Microsoft MSDN® XQuery language demonstration site at
http://131.107.228.20/xquerydemo/.

!

Run basic and advanced XQuery expressions by using the demonstration
site.

!

Relate the XQuery examples on the demonstration site to patterns of data
output that will result from any XQuery expression.

Note The files located in the install_folder\Labfiles\Mod08\Solution are the
sample XML files provided at http://131.107.228.20/xquerydemo/demo.aspx.
Only bib.xml is required to complete the lab. The rest are provided to allow you

to conveniently view the XML source files used by the demo queries.
Prerequisites

Before working on this lab, you must have a reasonable understanding of
XQuery syntax.
Note You can download the assemblies used to run the Web-based
demonstration so that you can try XQuery on your own sample files. Go to
http://131.107.228.20/xquerydemo/ and click Downloads for more information.

Estimated time to complete this lab: 20 minutes


×