Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

XML Querying with XQuery: Selecting, Filtering, and Transforming XML Data, Slides of Semantics of Programming Languages

Explore xquery, the w3c query language designed for handling xml data. Learn how to select, filter, search, join, sort, group, and transform xml data using xquery. Discover the capabilities of xquery and how to use it to query an xml catalog using path expressions and flwor expressions.

Typology: Slides

2011/2012

Uploaded on 07/11/2012

dharuna
dharuna 🇮🇳

4.7

(6)

87 documents

1 / 29

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
XML Query: xQuery
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download XML Querying with XQuery: Selecting, Filtering, and Transforming XML Data and more Slides Semantics of Programming Languages in PDF only on Docsity!

XML Query: xQuery

XML Data

  • Enormous amount of information is now stored in XML,
  • This includes highly structured data, such as sales figures,
  • Semi-structured data such as product catalogs and yellow pages,
  • and relatively unstructured data such as letters and books.
  • Even more information is passed between systems as transitory XML documents.
  • All of this data is used for a variety of purposes

Capabilities of XQuery

  1. Selecting information based on specific criteria
  2. Filtering out unwanted information
  3. Searching for information within a document or set of documents
  4. Joining data from multiple documents or collections of documents
  5. Sorting, grouping, and aggregating data
  6. Transforming and restructuring XML data into another XML vocabulary or structure
  7. Performing arithmetic calculations on numbers and dates
  8. Manipulating strings to reformat text

557 Fleece Pullover navy black 563 Floppy Sun Hat 443 Deluxe Travel Bag 784 Cotton Dress Shirt white gray Our favorite shirt!

catalog.xml

doc("catalog.xml")/catalog/product

  • doc("catalog.xml") calls an XQuery function named

doc, passing it the name of the file to open

  • catalog selects the catalog element, the outermost

element of the document

  • product selects all the product children of catalog
  • The result of the query will be the four product

elements, exactly as they appear (with the same attributes and contents) in the input document

557 Fleece Pullover navy black 563 Floppy Sun Hat 443 Deluxe Travel Bag 784 Cotton Dress Shirt white gray Our favorite shirt!

Path Expressions

  • Path expressions are convenient because of

their compact, easy-to-remember syntax.

  • However, they have a limitations:
    • they can only return elements and attributes as they appear in input documents.
    • Any elements selected in a path expression appear in the results with the same names, the same attributes and contents,
    • and in the same order as in the input document.

xQuery - FLWOR

  • The basic structure of many (but not all)

queries is the FLWOR expression

FLWOR

  • For
    • This clause sets up an iteration through the product nodes, and the rest of the FLWOR is evaluated once for each of the four products.
    • Each time, a variable named $prod is bound to a different product element.
    • Dollar signs are used to indicate variable names in XQuery. for $prod in doc(" catalog.xml")/catalog/product where $prod/@dept = "ACC" order by $prod/name return $prod/name Docsity.com

FLWORs

  • where
    • This clause selects only products in the ACC department.
    • This has the same effect as a predicate ([@dept = "ACC"]) in a path expression.

for $prod in doc("catalog.xml")/catalog/product where $prod/@dept = "ACC" order by $prod/name return $prod/name

FLWORs

  • order by
    • This clause sorts the results by product name, something that is not possible with path expressions.

for $prod in doc("catalog.xml")/catalog/product where $prod/@dept = "ACC" order by $prod/name return $prod/name

FLWORs

  • return
    • This clause indicates that the product element’s name children should be returned.

for $prod in doc("catalog.xml")/catalog/product where $prod/@dept = "ACC" order by $prod/name return $prod/name

FLWORs

  • The let clause serves as a programmatic

convenience that avoids repeating the same expression multiple times.

  • Using some implementations, it can also

improve performance, because the expression is evaluated only once instead of each time it is needed.

Wrap the results

  • wrap the results of your query in a different

XML vocabulary **Query

    {** for $product in doc("catalog.xml")/catalog/product where $product/@dept='ACC' order by $product/name return $product/name **}
……. Results**
    Deluxe Travel Bag Floppy Sun Hat