Example #1
0
book1 = <book><title>Knowledge Discovery in Databases.</title></book>
ACTUAL RESULT:
<?php 
#
# This is a very simple example of using try/catch and XmlException
# to get information on an exception thrown from Berkeley DB XML.
# The line that generates the exception is the query, which uses
# bad XQuery syntax.
#
$book_name = 'book1';
$book_content = '<book><title>Knowledge Discovery in Databases.</title></book>';
$mgr = new XmlManager();
try {
    $con = $mgr->createContainer("test.dbxml");
    $con->putDocument($book_name, $book_content);
    $qc = $mgr->createQueryContext();
    $res = $mgr->query("collection('test.dbxml')/x[", $qc);
    $doc = $con->getDocument("foo");
    $s = $doc->getContentAsString();
    print $doc->getName() . " = {$s}\n";
    unset($doc);
    unset($con);
} catch (XmlException $xe) {
    print "XmlException message: " . $xe->what() . "\n";
    print "XmlException code: " . $xe->getExceptionCode() . "\n";
    print "XmlException dbErrno: " . $xe->getDbErrno() . "\n";
    print "Query line: " . $xe->getQueryLine() . "\n";
    print "Query column: " . $xe->getQueryColumn() . "\n";
    unset($con);
}
$mgr->removeContainer("test.dbxml");
Example #2
0
File: 12.php Project: kanbang/Colt
Currently non-functional.
<?php 
$book_name = 'book1';
$book_content = '<book><title>Knowledge Discovery in Databases.</title></book>';
class myResolver extends XmlResolver
{
    function resolveDocument($uri, &$result)
    {
        print "In resolveDocument({$uri})\n";
        $result = new XmlValue("<a><b>b</b></a>");
        return true;
    }
    function resolveCollection($uri, &$result)
    {
        print "In resolveCollection({$uri})\n";
        return false;
    }
}
$r = new myResolver();
$mgr = new XmlManager();
$mgr->registerResolver($r);
$con = $mgr->createContainer("test.dbxml");
$con->putDocument($book_name, $book_content);
$results = $mgr->query("doc('myscheme:xxx')/root");
print_r($results);
Example #3
0
File: 03.php Project: kanbang/Colt
Create an XmlContainer, add a document that includes a
namespace definition, create a query context, define a
namespace prefix to URI mapping, query the container
for the document within a context, iterate over the
result set displaying the values returned.

EXPECTED RESULT:
book1_ns = <book xmlns:books="http://foo.bar.com/books.dtd"><books:title>Knowledge Discovery in Databases.</books:title></book>
ACTUAL RESULT:
<?php 
$book_name = 'book1_ns';
$book_content = "<book xmlns:books='http://foo.bar.com/books.dtd'><books:title>Knowledge Discovery in Databases.</books:title></book>";
$container_name = 'test.dbxml';
$mgr = new XmlManager(null);
if (file_exists("test.dbxml")) {
    $mgr->removeContainer("test.dbxml");
}
$con = $mgr->createContainer("test.dbxml");
$con->putDocument($book_name, $book_content);
$qc = $mgr->createQueryContext();
$qc->setNamespace("books2", "http://foo.bar.com/books.dtd");
$results = $mgr->query("collection('test.dbxml')/*[books2:title='Knowledge Discovery in Databases.']", $qc);
$results->reset();
while ($results->hasNext()) {
    $val = $results->next();
    $doc = $val->asDocument();
    print $doc->getName() . " = " . $val->asString() . "\n";
}
Example #4
0
File: 02.php Project: kanbang/Colt
Create an XmlManager/XmlContainer, add a document, query the container
for the document, iterate over the result set displaying the
values returned.

EXPECTED RESULT:
book1 = <book><title>Knowledge Discovery in Databases.</title></book>
ACTUAL RESULT:
<?php 
$book_name = 'book1';
$book_content = '<book><title>Knowledge Discovery in Databases.</title></book>';
$container_name = 'test.dbxml';
$mgr = new XmlManager();
if (file_exists("test.dbxml")) {
    $mgr->removeContainer("test.dbxml");
}
$con = $mgr->createContainer("test.dbxml");
$con->putDocument($book_name, $book_content);
$results = $mgr->query("collection('test.dbxml')/book");
$results->reset();
while ($results->hasNext()) {
    $val = $results->next();
    $doc = $val->asDocument();
    print $doc->getName() . " = " . $val->asString() . "\n";
}
Example #5
0
File: 05.php Project: kanbang/Colt
Create an XmlContainer, define an equality string index
for booktitle elements, add a document, create a query
context, define a variable binding, query the container
for the document within a context referencing the variable
defined, iterate over the result set displaying the values
returned.

EXPECTED RESULT:
book1 = <book><title>Knowledge Discovery in Databases.</title></book>
ACTUAL RESULT:
<?php 
$book_name = 'book1';
$book_content = "<book><title>Knowledge Discovery in Databases.</title></book>";
$container_name = 'test.dbxml';
unlink($container_name);
$mgr = new XmlManager(null);
$con = $mgr->createContainer("test.dbxml");
$con->addIndex("", "title", "node-element-equality-string");
$con->putDocument($book_name, $book_content);
$qc = $mgr->createQueryContext();
$qc->setVariableValue("title", "Knowledge Discovery in Databases.");
$results = $mgr->query("collection('test.dbxml')//*[title=\$title]", $qc);
$results->reset();
while ($results->hasNext()) {
    $val = $results->next();
    $doc = $val->asDocument();
    print $doc->getName() . " = " . $val->asString() . "\n";
}
Example #6
0
File: 04.php Project: kanbang/Colt
Create an XmlContainer, define an equality string index
for booktitle elements, add a document, query the container
for the document, iterate over the result set displaying
the values returned.

EXPECTED RESULT:
book1 = <book><title>Knowledge Discovery in Databases.</title></book>
ACTUAL RESULT:
<?php 
$book_name = 'book1';
$book_content = "<book><title>Knowledge Discovery in Databases.</title></book>";
$container_name = 'test.dbxml';
unlink($container_name);
$mgr = new XmlManager(null);
$con = $mgr->createContainer("test.dbxml");
$con->addIndex("", "title", "node-element-equality-string");
$con->putDocument($book_name, $book_content);
$results = $mgr->query("collection('test.dbxml')//*[title='Knowledge Discovery in Databases.']");
$results->reset();
while ($results->hasNext()) {
    $val = $results->next();
    $doc = $val->asDocument();
    print $doc->getName() . " = " . $val->asString() . "\n";
}