Table of Contents
BDB XML provides APIs for deleting, replacing, and modifying documents that are stored in containers. This chapter discusses these activities.
You can delete a document by calling
XmlContainer::deleteDocument().
This method can operate either on a document's name or on an
XmlDocument object. You might want to use an
XmlDocument object to delete a document if
you have queried your container for some documents and you want to
delete every document in the results set.
For example:
#include "DbXml.hpp"
...
using namespace DbXml;
...
// Get a manager object.
XmlManager myManager;
// Open a container
XmlContainer myContainer =
myManager.openContainer("exampleData.dbxml");
// Get a query context
XmlQueryContext context = myManager.createQueryContext();
// Declare a namespace
context.setNamespace("fruits", "http://groceryItem.dbxml/fruits");
// Declare the query string. Find all the product documents
// in the fruits namespace.
std::string myQuery = "collection('exampleData.dbxml')/fruits:product";
// Perform the query.
XmlResults results = myManager.query(myQuery, context);
// Delete everything in the results set
XmlUpdateContext uc = myManager.createUpdateContext();
XmlDocument theDoc = myManager.createDocument();
while (results.next(theDoc)) {
myContainer.deleteDocument(theDoc, uc);
}