Listing 1

#include <string>
#include <fstream>
#include "dbxml/DbXml.hpp"

using namespace std;
using namespace DbXml;

int
main(int argc, char **argv)
{
  try {
    XmlManager mgr;
    XmlUpdateContext uc = mgr.createUpdateContext();
    XmlQueryContext qc = mgr.createQueryContext();
    XmlContainer cont = mgr.createContainer("test.dbxml");

    cont.putDocument("myDoc",
	"<names><name>joe</name><name>jane</name></names>", uc);
    XmlResults res = mgr.query("collection('test.dbxml')/names/name[.='joe']", qc);
    XmlValue value;
    while (res.next(value))
      cout << "Value: " << value.asString() << endl;
  } catch (XmlException &e) {
    std::cout << "Exception: " << e.what() << std::endl;
  }
  return 0;
}

Listing 2

import java.io.*;
import com.sleepycat.dbxml.*;
import com.sleepycat.db.*;

class testSimple
{
public static void main(String args[]) throws Throwable {
    try {
	XmlManager mgr = new XmlManager();
	XmlUpdateContext uc = mgr.createUpdateContext();
	XmlQueryContext qc = mgr.createQueryContext();
	XmlContainer cont = mgr.createContainer("test.dbxml");

	cont.putDocument("myDoc",
	"<names><name>joe</name><name>jane</name></names>",uc);
	XmlResults res = mgr.query(
	  "collection('test.dbxml')/names/name[.='joe']", qc);
	while (res.hasNext()) {
	    XmlValue val = res.next();
	    System.out.println("Value: " + val.asString());
	}
    }
    catch (XmlException e) {
	System.out.println("XmlException: " + e.toString());
    }
    catch (Throwable t) {
	System.out.println("Threw: " + t);
    }
}

}

Listing 3

dbxml> query collection("parts")/part[parent-part]
300 objects returned for eager expression 'collection("parts")/part[parent-part]'
dbxml> print
<part number="540"><description>Description of 540</description><category>0</category><parent-part>0
</parent-part></part>
<part number="30"><description>Description of 30</description><category>0</category><parent-part>0
</parent-part></part>
...
<part number="990"><description>Description of 990</description><category>0</category><parent-part>0
</parent-part></part>
<part number="480"><description>Description of 480</description><category>0</category><parent-part>0
</parent-part></part>

Listing 4

dbxml> query collection("parts")/part[not(parent-part)]
2700 objects returned for eager expression 'collection("parts")/part[not(parent-part)]'
dbxml> print
<part number="22"><description>Description of 22</description><category>2</category></part>
<part number="1995"><description>Description of 1995</description><category>5</category></part>
...
<part number="2557"><description>Description of 2557</description><category>7</category></part>
<part number="2813"><description>Description of 2813</description><category>3</category></part>

Listing 5

dbxml> query 'collection("parts")/part[@number > 100 and @number < 105]'
4 objects returned for eager expression 'collection("parts")
/part[@number > 100 and @number < 105]'
dbxml> print
<part number="101"><description>Description of 101</description><category>1</category></part>
<part number="102"><description>Description of 102</description><category>2</category></part>
<part number="103"><description>Description of 103</description><category>3</category></part>
<part number="104"><description>Description of 104</description><category>4</category></part>