Figaro - The XML Database for the .NET Framework

You can delete a document by calling 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.

In a non-transactional environment, the delete changes are not committed to the container until the container is closed and re-opened.
CopyC#
using System;
using Figaro.BerkeleyDB.Xml;
namespace Figaro.Documentation.Examples
{
class DeletingDocuments
{
static void Main()
{
//get our manager
using (var mgr = new XmlManager(ManagerInitOptions.AllowExternalAccess | ManagerInitOptions.AllowAutoOpen))
{
prepareContainer(true);
//open a container
using (var container = mgr.OpenContainer(baseUri + testdb))
{
try
{
Console.WriteLine("container has {0} documents.", container.GetNumDocuments());
container.AddAlias("testdb");
// get a query context
QueryContext queryContext = mgr.CreateQueryContext();
UpdateContext updateContext = mgr.CreateUpdateContext();
queryContext.SetNamespace("fruits", "http://groceryItem.dbxml/fruits");
const string myQuery = "collection('testdb')/fruits:item";
try
{
using (var results = mgr.Query(myQuery, queryContext, QueryOptions.None))
{
Console.WriteLine("fruits query yielded {0} results.", results.Size);
while (results.HasNext())
{
container.DeleteDocument(results.NextDocument(), updateContext);
}
}
Console.WriteLine("container now contains {0} documents.",container.GetNumDocuments());
}
catch(XmlException)
{
Debugger.Break();
}
}
finally
{
container.Close();
}
}
}
}

See Also