/// <summary>
        /// Finds the schema given the xml element path.
        /// </summary>
        public XmlSchemaCompletionData FindSchema(XmlElementPath path)
        {
            if (path.Elements.Count > 0) {
                string namespaceUri = path.Elements[0].Namespace;
                if (namespaceUri.Length > 0) {
                    var result = schemaCompletionDataItems[namespaceUri];
              if (result == null && defaultSchemaCompletionData.NamespaceUri == namespaceUri) result = defaultSchemaCompletionData;
              return result;
                } else if (defaultSchemaCompletionData != null) {

                    // Use the default schema namespace if none
                    // specified in a xml element path, otherwise
                    // we will not find any attribute or element matches
                    // later.
                    foreach (QualifiedName name in path.Elements) {
                        if (name.Namespace.Length == 0) {
                            name.Namespace = defaultSchemaCompletionData.NamespaceUri;
                        }
                    }
                    return defaultSchemaCompletionData;
                }
            }
            return null;
        }
        ICompletionData[] GetChildElementCompletionData(XmlElementPath path)
        {
            ICompletionData[] completionData = null;

            XmlSchemaCompletionData schema = FindSchema(path);
            if (schema != null) {
                completionData = schema.GetChildElementCompletionData(path);
            }

            return completionData;
        }
        ICompletionData[] GetAttributeValueCompletionData(XmlElementPath path, string name)
        {
            ICompletionData[] completionData = null;

            XmlSchemaCompletionData schema = FindSchema(path);
            if (schema != null) {
                completionData = schema.GetAttributeValueCompletionData(path, name);
            }

            return completionData;
        }
        /// <summary>
        /// Gets the child element completion data for the xml element that exists
        /// at the end of the specified path.
        /// </summary>
        public ICompletionData[] GetChildElementCompletionData(XmlElementPath path)
        {
            XmlCompletionDataCollection data = new XmlCompletionDataCollection();

              // Locate matching element.
              XmlSchemaElement element = FindElement(path);

              // Get completion data.
              if (element != null)
              {
            data = GetChildElementCompletionData(element, path.Elements.LastPrefix);
              }

              return data.ToArray();
        }
        /// <summary>
        /// Gets the autocomplete data for the specified attribute value.
        /// </summary>
        public ICompletionData[] GetAttributeValueCompletionData(XmlElementPath path, string name)
        {
            XmlCompletionDataCollection data = new XmlCompletionDataCollection();

              // Locate matching element.
              XmlSchemaElement element = FindElement(path);

              // Get completion data.
              if (element != null)
              {
            data = GetAttributeValueCompletionData(element, name);
              }

              return data.ToArray();
        }
        /// <summary>
        /// Gets the attribute completion data for the xml element that exists
        /// at the end of the specified path.
        /// </summary>
        public ICompletionData[] GetAttributeCompletionData(XmlElementPath path)
        {
            XmlCompletionDataCollection data = new XmlCompletionDataCollection();

              // Locate matching element.
              XmlSchemaElement element = FindElement(path);

              // Get completion data.
              if (element != null)
              {
            prohibitedAttributes.Clear();
            data = GetAttributeCompletionData(element);
              }

              return data.ToArray();
        }
 /// <summary>
 /// Finds the element that exists at the specified path.
 /// </summary>
 /// <remarks>This method is not used when generating completion data,
 /// but is a useful method when locating an element so we can jump
 /// to its schema definition.</remarks>
 /// <returns><see langword="null"/> if no element can be found.</returns>
 public virtual XmlSchemaElement FindElement(XmlElementPath path)
 {
     XmlSchemaElement element = null;
       for (int i = 0; i < path.Elements.Count; ++i)
       {
     QualifiedName name = path.Elements[i];
     if (i == 0)
     {
       // Look for root element.
       element = FindElement(name);
       if (element == null)
       {
     break;
       }
     }
     else
     {
       element = FindChildElement(element, name);
       if (element == null)
       {
     break;
       }
     }
       }
       return element;
 }