Connect to PHP

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mokka mit Schlag</title>
</head>
<body>

<?php
$mgr = new XmlManager(null);
$con = $mgr->openContainer("website.dbxml");
$results = $mgr->query("
    declare namespace atom='http://www.w3.org/2005/Atom';
    declare namespace html='http://www.w3.org/1999/xhtml';
    <h1 xmlns='http://www.w3.org/1999/xhtml'> { 
     string(doc('website.dbxml/pages')/atom:feed/atom:title) 
    } </h1>,
    for $entry in doc('website.dbxml/pages')//atom:entry
    return
      <div xmlns='http://www.w3.org/1999/xhtml'>
      <h2> { string($entry/atom:title) } </h2>
      { $entry/atom:content/html:div } 
      </div>
");

// XQueries return sequences so you have to 
// iterate through them to get all the results
$results->reset();
while($results->hasNext()) 
{
    $val = $results->next();
    print $val->asString();
}
 
?>

<p>
Of course as usual, you can put other HTML markup
and PHP scripts in the document where you like.
However since this is exactly what XQuery databases are
optimized for and XQuery is designed for, I tend to 
prefer to do as much of my heavy lifting in XQuery as possible.
</p>

<p>
Generally speaking, you can get a lot more web work done in a native 
XML database than in a SQL database because XQuery is designed to
generate complete documents, while SQL is designed only to produce tables
that then need to be further massaged into document form for
human consumption. 
</p>

</body>
</html>

Previous | Next | Top | Cafe con Leche | Cafe au Lait

Copyright 2002-2007 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified October 23, 2007