This article is more than 1 year old

An embedded XML Database: Oracle Berkeley DB XML

There is more to life than RDBMS

Modifying XML Documents

The Oracle BDB XML command shell provides various commands such as append, insertAfter and insertBefore to modify an XML document in the database. The append command won’t append an attribute if the context has not been set. The query expression for modifying nodes should be relative; it should navigate from the context item “.” rather than evaluating an expression with the collection() or doc() function. The context is set prior to the modifications with the query command. For example, set the context to the catalog.dbxml container:

dbxml> query 'collection("catalog.dbxml")'

Having set the context we may run an append command. As an example add an ‘article’ node:

dbxml> append 
 './catalog/journal[article/title="Using Bind Variables"]' 
 'element' 'article'
 ASM</title><author>Arup Nanda</author>'

Retrieve the modified “catalog1” document with the getDocuments command and output the document with the print command – see Figure 6.

Outputting Modified Document.

Using the Berkeley DB XML API

In BDB XML documents are stored in containers. Containers are of two types; Wholedoc containers and Node containers. A Wholedoc container stores the complete XML document without any modifications to line breaks or whitespaces. In a Node container, XML documents are stored as nodes. BDB XML also stores information about reassembling an XML document from the nodes stored in the database. The Node container is preferred and is the default type. A comparison of Node container and Wholedoc container is discussed in the Table below:

Container Type Storage Mode Query Performance Load Performance Application
Node Container XML document stored in nodes Faster to query Lower load performance Use Node container if faster query performance is required. Use Node container if document size is more than 1MB.
Wholedoc Container Whole XML document stored Lower query performance, because complete document has to be navigated Faster document loading, because an XML document does not have to be deconstructed into nodes Use Wholedoc container if load performance is more important than query performance. Use Wholedoc container if document is relatively small and requires to be frequently retrieved.

An XmlManager object is used to manage many of the objects used in a BDB XML application, including managing an XmlContainer and preparing and running XQuery queries. Create an XmlManager object and set the default container type to be Node container.

XmlManager xmlManager = new XmlManager();

Next, create a container, catalog.dbxml. The container is the BDB XML database:

XmlContainer xmlContainer = xmlManager.createContainer("catalog.dbxml");

More about


Send us news

Other stories you might like