/// <summary> /// Gets the active element path given the element text. /// </summary> private static XmlElementPath GetActiveElementStartPath(string xml, int index, string elementText, QualifiedNameCollection namespaces) { QualifiedName elementName = GetElementName(elementText); if (elementName == null) { return(new XmlElementPath()); } NamespaceURI elementNamespace = GetElementNamespace(elementText); XmlElementPath path = GetFullParentElementPath(xml.Substring(0, index), namespaces); // Try to get a namespace for the active element's prefix. if (elementName.Prefix.Length > 0 && elementNamespace.Namespace.Length == 0) { elementName.Namespace = GetNamespaceForPrefix(namespaces, elementName.Prefix); elementNamespace.Namespace = elementName.Namespace; elementNamespace.Prefix = elementName.Prefix; } if (elementNamespace.Namespace.Length == 0) { if (path.Elements.Count > 0) { QualifiedName parentName = path.Elements[path.Elements.Count - 1]; elementNamespace.Namespace = parentName.Namespace; elementNamespace.Prefix = parentName.Prefix; } } path.Elements.Add(new QualifiedName(elementName.Name, elementNamespace.Namespace, elementNamespace.Prefix)); path.Compact(); return(path); }
/// <summary> /// Gets the parent element path based on the index position. /// </summary> public static XmlElementPath GetParentElementPath(string xml) { QualifiedNameCollection namespaces = new QualifiedNameCollection(); XmlElementPath path = GetFullParentElementPath(xml, namespaces); path.Compact(); return(path); }