session_start();
set_magic_quotes_runtime (0);
$example=Array();
$example["query"]=Array(
'
{
for $b in xmlmem($bib)/bib/book
where $b/publisher = "Addison-Wesley" and $b/@year > 1991
return
{ $b/title }
}
',
'
{
for $b in xmlmem($bib)/bib/book,$t in $b/title,$a in $b/author
return
{ $t }
{ $a }
}
',
'
{
for $b in xmlmem($bib)/bib/book
return
{ $b/title }
{ $b/author }
}
',
'
{
for $a in distinct-values(xmlmem($bib)//author)
return
{$a }
{
for $b in xmlmem($bib)/bib/book
for $a2 in $b/author
where $a2=$a
return {$b/title}
}
}
',
'
{
for $b in xmlmem($bib)//book,
$a in xmlmem($reviews)//entry
where $b/title = $a/title
return
{ $b/title }
{ $a/price/text() }{ $b/price/text() }
}
',
'
{
for $b in xmlmem($bib)//book
where count($b/author) > 2
return
{ $b/title }
{
for $a in $b/author[position()<=2]
return {$a}
}
}
{
for $b in xmlmem($bib)//book
where count($b/author) <= 2
return
{ $b/title }
{
for $a in $b/author[position()<=2]
return {$a}
}
}
',
'',
'',
'
{
for $t in xmlmem($bib)//title[contains(./text(),"XML")]
return {$t}
}
',
'',
'
{
for $b in xmlmem($bib)//book[author]
return
{ $b/title }
{ $b/author }
}
{
for $b in xmlmem($bib)//book[editor]
return
{ $b/title }
{$b/editor/affiliation}
}
','');
$example["text"]=Array('List books published by Addison-Wesley after 1991, including their year and title.',
'Create a flat list of all the title-author pairs, with each pair enclosed in a "result" element.',
'For each book in the bibliography, list the title and authors, grouped inside a "result" element.',
'For each author in the bibliography, list the author\'s name and the titles of all books by that author, grouped inside a "result" element.',
'For each book found at both bn.com and amazon.com, list the title of the book and its price from each source.',
'For each book that has at least one author, list the title and first two authors, and an empty "et-al" element if the book has additional authors.',
'List the titles and years of all books published by Addison-Wesley after 1991, in alphabetic order.',
'Find books in which the name of some element ends with the string "or" and the same element contains the string "Suciu" somewhere in its content. For each such book, return the title and the qualifying element.',
'In the xmlmem "bib.xml", find all titles that contain the word "XML", regardless of the level of nesting.',
'In the xmlmem "prices.xml", find the minimum price for each book, in the form of a "minprice" element with the book title as its title attribute.',
'For each book with an author, return the book with its title and authors. For each book with an editor, return a reference with the book title and the editor\'s affiliation. ',
'Find pairs of books that have different titles but the same set of authors (possibly in a different order).');
if(!isset($_SESSION["bib"])) {
$bib='TCP/IP IllustratedStevensW.Addison-Wesley 65.95Advanced XML Programming in the Unix environmentStevensW.Addison-Wesley65.95Data on the WebAbiteboulSergeBunemanPeterSuciuDanMorgan Kaufmann Publishers 39.95The Economics of Technology and Content for Digital TVGerbargDarcyCITIKluwer Academic Publishers129.95';
session_register("bib");
}
if(!isset($_SESSION["reviews"])) {
$reviews='Data on the Web34.95
A very good discussion of semi-structured database
systems and XML.
Advanced Programming in the Unix environment65.95
A clear and detailed discussion of UNIX programming.
TCP/IP Illustrated65.95
One of the best books on TCP/IP.
';
session_register("reviews");
}
if(isset($_REQUEST["set"])) {
$varname=$_REQUEST["varname"];
// We process an update here
${$varname}=stripslashes($value);
session_register("$varname");
}
if(isset($_REQUEST["recover"])) {
session_unregister("bib");
session_unregister("reviews");
unset($bib);
unset($reviews);
}
?>
Xquery Lite demo(PHP)
Xquery Lite demo
This demo explains how to solve the W3C "XMP" use cases using Xquery Lite 1.0.
The PHP implementation of Xquery Lite is used to show how the queries are evaluated and you can test your own queries too.
This is a list of the XML xmlmems used in the demo, xmlmems can be
edited (under your own risk). If you mess things up click here to Recover the original examples