Docsity

INFS 740: Database Programming with XQuery - XML and XQuery Examples - Prof. Alexander Bro, Study notes of Database Programming

Partial preview of the text

Download INFS 740: Database Programming with XQuery - XML and XQuery Examples - Prof. Alexander Bro and more Study notes Database Programming in PDF only on Docsity!

INFS 740, Prof. A. Brodsky, IT&E, GMU. Based on material by Prof. X.S. Wang, UVM

INFS 740

Database Programming for the

WEB

XQuery

Prof. Alex Brodsky

GMU

XML Example users.xml INFS 740, Prof. A. Brodsky, IT&E, GMU. Based on material by Prof. X.S. Wang, UVM

<user_tuple>

U01Tom JonesB </user_tuple><user_tuple>

U02Mary DoeA </user_tuple><user_tuple>

U03Dee LinquentD </user_tuple>

<user_tuple>

U04Roger SmithC

</user_tuple><user_tuple>

U05Jack SpratB

</user_tuple><user_tuple>

U06Rip Van WinkleB

</user_tuple>

INFS 740, Prof. A. Brodsky, IT&E, GMU. Based on material by Prof. X.S. Wang, UVM

Another Example

{ for $u in $users//user_tuple,

$i in $items//item_tuplewhere($u/rating > "C" and $i/reserve_price > 1000and $i/offered_by = $u/userid)return{$u/name}{$u/rating}{$i/description}{$i/reserve_price}

}

INFS 740, Prof. A. Brodsky, IT&E, GMU. Based on material by Prof. X.S. Wang, UVM

Basic Ideas Of XQuery

• Value expressions• Sequences of values• Use XPath expression to “navigate” on the

XML tree, to get values or sequences ofvalues

INFS 740, Prof. A. Brodsky, IT&E, GMU. Based on material by Prof. X.S. Wang, UVM

Loops

•Use FLWR expressions to loop through sequences

–Example

for $u in $users/users/user_tuplelet $n := $u/namewhere ($u/rating=“A”)return $n

INFS 740, Prof. A. Brodsky, IT&E, GMU. Based on material by Prof. X.S. Wang, UVM

Data Types

• Literals• Complex type: Element type using XML

Schema^ define element bid_count { element itemno,

element nbids { xsd:int } }

INFS 740, Prof. A. Brodsky, IT&E, GMU. Based on material by Prof. X.S. Wang, UVM

More Examples

http://www.research.avayalabs.com/user/wadl

er/papers/xquery-tutorial/xquery-tutorial.pdf