/// <summary>
        /// Gets the active element path given the element text.
        /// </summary>
        static XmlElementPath GetActiveElementStartPath(string xml, int index, string elementText)
        {
            QualifiedName elementName = GetElementName(elementText);

            if (elementName.IsEmpty)
            {
                return(new XmlElementPath());
            }

            XmlNamespace elementNamespace = GetElementNamespace(elementName, elementText);

            XmlElementPath path = GetFullParentElementPath(xml.Substring(0, index));

            // Try to get a namespace for the active element's prefix.
            if (elementName.HasPrefix && !elementNamespace.HasName)
            {
                elementName.Namespace   = path.GetNamespaceForPrefix(elementName.Prefix);
                elementNamespace.Name   = elementName.Namespace;
                elementNamespace.Prefix = elementName.Prefix;
            }

            if (!elementNamespace.HasName)
            {
                if (path.Elements.Count > 0)
                {
                    QualifiedName parentName = path.Elements[path.Elements.Count - 1];
                    elementNamespace.Name   = parentName.Namespace;
                    elementNamespace.Prefix = parentName.Prefix;
                }
            }
            path.AddElement(new QualifiedName(elementName.Name, elementNamespace));
            //path.AddElement(new QualifiedName(elementName.Name, elementName.Namespace, elementName.Prefix));
            return(path);
        }
        /// <summary>
        /// Gets the name of the attribute and its prefix at the specified index. The index
        /// can be anywhere inside the attribute name or in the attribute value.
        /// The namespace for the element containing the attribute will also be determined
        /// if the includeNamespace flag is set to true.
        /// </summary>
        public static QualifiedName GetQualifiedAttributeNameAtIndex(string xml, int index, bool includeNamespace)
        {
            string        name          = GetAttributeNameAtIndex(xml, index);
            QualifiedName qualifiedName = QualifiedName.FromString(name);

            if (!qualifiedName.IsEmpty && !qualifiedName.HasNamespace && includeNamespace)
            {
                XmlElementPath path = GetActiveElementStartPathAtIndex(xml, index);
                qualifiedName.Namespace = path.GetNamespaceForPrefix(path.Elements.GetLastPrefix());
            }
            return(qualifiedName);
        }