Figaro - The XML Database for the .NET Framework

To add an index to a container:

  1. Retrieve the index specification from the container.
  2. Use AddIndex to add the index to the container. You must provide to this method the namespace and node name to which the index is applied. You must also identify the indexing strategy.

    If the index already exists for the specified node, then the method silently does nothing.

  3. Set the updated index specification back to the container.
For example:
CopyC#
using System;
using Figaro.BerkeleyDB.Xml;
namespace Figaro.Documentation.Examples
{
    class AddIndexSpecification
    {
        private const string baseUri = @"D:\dev\db\";
        private const string testdb = "AddIndexSpecification.dbxml";
        private const string testdata = @"D:\dev\db\xmlData\nsData\";

    static void Main()
    {
        //get our manager
        var mgr = new XmlManager(ManagerInitOptions.AllowExternalAccess | ManagerInitOptions.AllowAutoOpen);
        prepareContainer(true);
        //open a container
        Container container = mgr.OpenContainer(baseUri + testdb);
        try
        {
            XmlIndexSpecification xis = container.GetIndexSpecification();
            xis.AddIndex(new XmlIndex { Index = "node-element-presence-none", NodeName = "node1" ,Namespace=String.Empty });
            container.SetIndexSpecification(xis, mgr.CreateUpdateContext());
        }
        finally
        {
            container.Close();
        }
    }
}