// PLEASE CHANGE THIS TO POINT TO YOUR XINDICE SERVER
$server="localhost";
$port=4080;
$base="/db";
include_once("class_xindice.php");
print("
");
// Create the Xindice access object
$xi=new Xindice("$server",$port);
if(!$xi) {
die("Cannot create Xindice object, check servername and port
");
}
$xi->setXmlRpcDebug(0);
// Create a collection "pepe" under db
$xi->createCollection($base,"pepe");
// Insert a sample document there
$a_doc='
Foo
10
Goo
83
';
$xi->insertDocument("$base/pepe","cosa",$a_doc);
// List collections under base, should be an Array with "system" and "pepe"
$cols=$xi->listCollections($base);
print("Collections under $base: |
");
foreach($cols as $col) {
print("Collection | $col |
");
}
print("
");
// List number of documents under base/pepe should be 1 (the inserted doc)
$tot=$xi->getDocumentCount($base."/pepe");
print("Documents in $base/pepe: $tot |
");
if($tot==1) {
print("Test passed ok |
");
}
print("
");
// List the documents under base/pepe should be "cosa"
$docs=$xi->listDocuments($base."/pepe");
print("Documents in $base/pepe: $tot |
");
foreach($docs as $doc) {
print("Document | $doc |
");
}
print("
");
// Retrieve the "cosa" document
$cosa=$xi->getDocument($base."/pepe","cosa");
print("Document cosa: |
");
print(" |
");
print("
");
// Remove the document
$xi->removeDocument($base."/pepe","cosa");
// List number of documents under base/pepe should be 0
$tot=$xi->getDocumentCount($base."/pepe");
print("Documents in $base/pepe after removal: $tot |
");
if($tot==0) {
print("Test passed ok |
");
}
print("
");
// Re-insert the document
$xi->insertDocument($base."/pepe","cosa",$cosa);
// Make an Xpath query on the collection
$query=$xi->queryCollection($base."/pepe","XPath","//name");
print("Query result (queryCollection): |
");
print(" |
");
print("
");
// And the document
$query=$xi->queryDocument($base."/pepe","XPath","//name","cosa");
print("Query result (queryDocument): |
");
print(" |
");
print("
");
// An Xupdate modification
$modification=' Pirincho2
';
$query=$xi->queryDocument($base."/pepe","XUpdate","$modification","cosa");
// Retrieve the updated document
$cosa=$xi->getDocument("/db/pepe","cosa");
print("Updated document: |
");
print(" |
");
print("
");
// Drop the test collection
//$xi->dropCollection($base."/pepe");
?>