An embedded XML Database: Oracle Berkeley DB XML

There is more to life than RDBMS

Adding XML Documents

Similar to the putDocument shell command, the BDB XML API provides a method putDocument() to store an XML document in a database. Create a String object that represents an XML document and specify a document name:

String docString =”<catalog>  … </catalog>”;
String docName = "catalog1";

Create an XmlUpdateContext object. An XmlUpdateContext object represents the context within which update operations are performed in a container:

XmlUpdateContext updateContext = xmlManager.createUpdateContext(); 

Now store the XML document:

xmlContainer.putDocument(docName, docString, updateContext, null);

Similarly, add another XML document as shown in in the file.

Querying XML Documents with Xquery

Next, we’ll query the XML documents in the catalog.dbxml BDXML database using XQuery. First, we create an XmlQueryContext object representing the context within which an XML document in a container is queried:

XmlQueryContext context = xmlManager.createQueryContext();

As an example, retrieve the values of all the titles in the BDB XML database. Specify the query string that represents the XQuery expression for the query:

String query = "collection('catalog.dbxml')/catalog/journal/article/title/text()";

Now compile the XQuery expression:

XmlQueryExpression qe = xmlManager.prepare(query, context);

Next, evaluate the XQuery expression:

XmlResults results = qe.execute(context);

Iterate over the results and output the titles retrieved:

while (results.hasNext()) {
XmlValue xmlValue =;

The output from the query is as follows:

Using Bind Variables
From Application Express to XE

Similar topics

Other stories you might like

Biting the hand that feeds IT © 1998–2022