CS1655 Recitation 7 XQuery Examples - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

CS1655 Recitation 7 XQuery Examples

Description:

CS1655 Recitation 7 XQuery Examples – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 8
Provided by: Am69
Category:

less

Transcript and Presenter's Notes

Title: CS1655 Recitation 7 XQuery Examples


1
CS1655 - Recitation 7XQuery Examples
  • Andreea Munteanu
  • andreea_at_cs.pitt.edu

2
Example books.xml
  • ltbooksgt
  • ltbookgt
  • lttitlegt Introduction to C lt/titlegt
  • ltauthorgt
  • ltfirstnamegt John lt/firstnamegt
  • ltlastnamegt Smith lt/lastnamegt
  • lt/authorgt
  • ltpricegt 100 lt/pricegt
  • lt/bookgt
  • .
  • lt/booksgt

3
Example 1(xquery)
  • for b in doc(books.xml)//book
  • where b/author/firstname John
  • and b/author/lastname Smith
  • return ltbookgt
  • b/title,
  • b/price
  • lt/bookgt

4
Example 1 Result
  • ltbookgt
  • lttitlegt Introduction to Clt/titlegt
  • ltpricegt 100 lt/pricegt
  • lt/bookgt
  • ltbookgt
  • lttitlegt Java quick reference lt/titlegt
  • ltpricegt 40 lt/pricegt
  • lt/bookgt

5
Authors.xml
  • ltauthorsgt
  • ltauthorgt
  • ltnamegt John Smith lt/namegt
  • ltaddressgt
  • ltstreetgt Hope Ave, 17 lt/streetgt
  • ltcitygt Pittsburgh lt/citygt
  • ltstategt PA lt/stategt
  • lt/addressgt
  • lt/authorgt
  • lt/authorsgt

6
Example 2 (xquery)
  • let a doc("authors.xml")
  • for b in doc("books.xml")//book
  • where contains(b/author/firstname,
    "John")
  • and contains(b/author/lastname,
    "Smith")
  • return
  • for c in (a/authors/)
  • return
  • for d in c
  • where contains(d/name, "John
    Smith")
  • return
  • ltstreetgt
  • d/address/street/text()
  • lt/streetgt

7
Example 2 Result
  • ltresultgt
  • ltstreetgt Hope Ave, 17 lt/streetgt
  • ltstreetgt Hope Ave, 17 lt/streetgt
  • lt/resultgt
Write a Comment
User Comments (0)
About PowerShow.com