1 import com
.sleepycat
.db
.Environment
;
2 import com
.sleepycat
.db
.EnvironmentConfig
;
3 import com
.sleepycat
.dbxml
.*;
7 public class CeisQuery
{
11 File envHome
= new File("xmlEnvironment");
12 XmlManager myManager
= null;
13 XmlContainer myContainer
= null;
16 /* Create the environment. */
17 EnvironmentConfig envConf
= new EnvironmentConfig();
18 envConf
.setAllowCreate(false);
19 envConf
.setInitializeCache(true);
20 myEnv
= new Environment(envHome
, envConf
);
22 /* Create the manager. */
23 XmlManagerConfig managerConfig
= new XmlManagerConfig();
24 managerConfig
.setAdoptEnvironment(true);
25 myManager
= new XmlManager(myEnv
, managerConfig
);
27 /* Open the container. */
28 myContainer
= myManager
.openContainer("ceis.dbxml");
30 // Get a query context
31 XmlQueryContext context
= myManager
.createQueryContext();
32 context
.setReturnType(XmlQueryContext
.LiveValues
);
33 context
.setEvaluationType(XmlQueryContext
.Eager
);
35 // Declare the query string
36 String myQuery
= "for $s in doc(\"dbxml:ceis.dbxml/ceis.xml\")/ceis/students/student return <studentid>{$s/studentid/string()}</studentid>";
37 XmlQueryExpression qe
= myManager
.prepare(myQuery
, context
);
38 /* Execute the query. */
39 XmlResults results
= qe
.execute(context
);
41 /* Display the results. */
42 System
.out
.printf("Count=%d%n", results
.size());
43 XmlValue value
= results
.next();
44 while (value
!= null) {
45 /* Get the xml returned by query. */
46 String result
= value
.asString();
49 System
.out
.printf("result= %s%n", result
);
51 /* Get the next value returned by the query. */
52 value
= results
.next();
59 } catch (Exception e
) {
62 /* Close the container and the manager (manager closes environment). */
64 if (myContainer
!= null) {
66 System
.out
.println("Container closed.");
68 if (myManager
!= null) {
70 System
.out
.println("Manager closed.");
72 System
.out
.println("End of program.");
73 } catch (XmlException ce
) {
79 public static void main(String
[] args
) {
80 CeisQuery application
= new CeisQuery();