/// <summary>
 /// Make the Consignments enumerable according to the CREATE section of the doc.
 /// Then index the Consignments for each of the relevant sections.
 /// Assumption: The CREATE section exists, or we have no Consignments.
 /// </summary>
 private bool Initialize(IndexBy indexBy)
 {
     IdPropertyXPath = XPathExpression.Compile("./" + indexBy.ToString() + "/text()");
     //determine available sections
     hasCreate       = doc.NodeExists("/document/CREATE");
     hasBook         = doc.NodeExists("/document/BOOK");
     hasShip         = doc.NodeExists("/document/SHIP");
     hasPrint        = doc.NodeExists("/document/PRINT");
     hasError        = doc.NodeExists("//ERROR");
     hasRuntimeError = doc.NodeExists("/runtime_error");
     //prepare iterator and indexes
     if (doc.NodeExists("/document"))
     {
         if (hasCreate)
         {
             createEnum  = doc.GetChildEnumerable(XPathExpression.Compile("/document"), "CREATE");
             createIndex = doc.GetChildIndex(XPathExpression.Compile("/document"), "CREATE", IdPropertyXPath);
         }
         if (hasBook)
         {
             bookIndex = doc.GetChildIndex(XPathExpression.Compile("/document/BOOK"), "CONSIGNMENT", IdPropertyXPath);
         }
         if (hasShip)
         {
             shipIndex = doc.GetChildIndex(XPathExpression.Compile("/document/SHIP"), "CONSIGNMENT", IdPropertyXPath);
         }
         //...etc
         return(true);
     }
     else
     {
         return(false); //after all, not worthy of further investigation.
     }
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="doc">MyXMLDocument that has a navigator focussed on the node whose children we want to index</param>
        /// <param name="multiChildName">Name of a node that may occur multiple times under the given node</param>
        public MyXMLChildIndex(MyXMLDocument doc, string multiChildName, XPathExpression propertyXPath)
        {
            this.index = new Dictionary <string, MyXMLDocument>();
            var iter = new MyXMLChildEnumerable(doc, multiChildName);

            foreach (MyXMLDocument node in iter)
            {
                string key = node.nav.SelectSingleNode(propertyXPath).Value;
                index.Add(key, node);
            }
        }