server-php-xml-class-xindice-test.php / php
<? // PLEASE CHANGE THIS TO POINT TO YOUR XINDICE SERVER port=4080; <table width='600' bgcolor='#9999cc' border='1' bordercolor='#000000'><tr><td><h3>Testing Xindice</h3></td></tr></table><br />"); // Create the Xindice access object xi=new Xindice("port); if(!<br />"); } xi->setXmlRpcDebug(0); // Create a collection "pepe" under db base,"pepe"); // Insert a sample document there <cosa> <person> <name>Foo</name> <age>10</age> </person> <person> <name>Goo</name> <age>83</age> </person> </cosa>'; xi->insertDocument("a_doc); // List collections under base, should be an Array with "system" and "pepe" xi->listCollections(<table width='600' bgcolor='#ccccff' border='1' bordercolor='#000000'><tr><td colspan='2' bgcolor='#9999cc'>Collections under base:</td></tr>"); foreach(col) { print("<tr><td>Collection</td><td></td></tr>"); } print("</table><br/>"); // List number of documents under base/pepe should be 1 (the inserted doc) tot=base."/pepe"); print("<table width='600' bgcolor='#ccccff' border='1' bordercolor='#000000'><tr><td bgcolor='#9999cc'>Documents in tot</td></tr>"); if(<tr><td>Test passed ok</td></tr></table>"); } print("<br/>"); // List the documents under base/pepe should be "cosa" docs=base."/pepe"); print("<table width='600' bgcolor='#ccccff' border='1' bordercolor='#000000'><tr><td colspan='2' bgcolor='#9999cc'>Documents in tot</td></tr>"); foreach(doc) { print("<tr><td>Document</td><td></td></tr></table>"); } print("<br/>"); // Retrieve the "cosa" document cosa=base."/pepe","cosa"); print("<table width='600' bgcolor='#ccccff' border='1' bordercolor='#000000'><tr><td bgcolor='#9999cc'>Document cosa:</td></tr>"); print("<tr><td><textarea rows='11' cols='40'></textarea></td></tr></table>"); print("<br />"); // Remove the document xi->removeDocument(// List number of documents under base/pepe should be 0 tot=base."/pepe"); print("<table width='600' bgcolor='#ccccff' border='1' bordercolor='#000000'><tr><td bgcolor='#9999cc'>Documents in tot</td></tr>"); if(<tr><td>Test passed ok</td></tr></table>"); } print("<br />"); // Re-insert the document xi->insertDocument(cosa); // Make an Xpath query on the collection xi->queryCollection(//name"); print("<table width='600' bgcolor='#ccccff' border='1' bordercolor='#000000'><tr><td bgcolor='#9999cc'>Query result (queryCollection):</td></tr>"); print("<tr><td><textarea rows='11' cols='40'>query</textarea></td></tr></table>"); print("<br />"); // And the document xi->queryDocument(//name","cosa"); print("<table width='600' bgcolor='#ccccff' border='1' bordercolor='#000000'><tr><td bgcolor='#9999cc'>Query result (queryDocument):</td></tr>"); print("<tr><td><textarea rows='11' cols='40'>query</textarea></td></tr></table>"); print("<br />"); // An Xupdate modification <?xml version="1.0"?> <xupdate:modifications version="1.0" xmlns:xupdate="http://www.xmldb.org/xupdate"> <xupdate:insert-after select="/cosa/person[1]" > <xupdate:element name="person"><name>Pirincho</name><age>2</age></xupdate:element></xupdate:insert-after></xupdate:modifications> '; query=base."/pepe","XUpdate","// Retrieve the updated document cosa=<table width='600' bgcolor='#ccccff' border='1' bordercolor='#000000'><tr><td bgcolor='#9999cc'>Updated document:</td></tr>"); print("<tr><td><textarea rows='11' cols='40'>cosa</textarea></td></tr></table>"); print("<br />"); // Drop the test collection //base."/pepe"); ?>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.