本文整理汇总了PHP中XmlManager::query方法的典型用法代码示例。如果您正苦于以下问题:PHP XmlManager::query方法的具体用法?PHP XmlManager::query怎么用?PHP XmlManager::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlManager
的用法示例。
在下文中一共展示了XmlManager::query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: XmlManager
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");
示例2: resolveDocument
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);
示例3: XmlManager
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";
}
示例4: XmlManager
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";
}
示例5: XmlManager
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";
}
示例6: XmlManager
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";
}