Ejemplo n.º 1
0
        /// <summary>
        /// Gets XmlPath information of the specified OpenXmlElement.
        /// </summary>
        /// <param name="element">The OpenXmlElement.</param>
        /// <returns>XmlPath to this element from root element.</returns>
        internal static XmlPath GetXPath(OpenXmlElement element)
        {
            if (element == null)
            {
                return null;
                // throw new ArgumentNullException("element");
            }

            XmlPath xmlPath = new XmlPath();
            
            xmlPath.PartUri = element.GetPartUri();

            Dictionary<string, string> namespaces = new Dictionary<string, string>();

            StringBuilder xpath = new StringBuilder("");

            BuildXPath(element, xpath, namespaces);

            xmlPath.XPath = xpath.ToString();

            StringBuilder nsString;

            foreach (var ns in namespaces)
            {
                nsString = new StringBuilder("");
                nsString.Append("xmlns:");
                nsString.Append(ns.Key);
                nsString.Append("=\"");
                nsString.Append(ns.Value);
                nsString.Append("\"");
                xmlPath.NamespacesDefinitions.Add(nsString.ToString());
            }

            return xmlPath;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets XmlPath information of the specified OpenXmlElement.
        /// </summary>
        /// <param name="element">The OpenXmlElement.</param>
        /// <returns>XmlPath to this element from root element.</returns>
        internal static XmlPath GetXPath(OpenXmlElement element)
        {
            if (element == null)
            {
                return(null);

                // throw new ArgumentNullException(nameof(element));
            }

            XmlPath xmlPath = new XmlPath();

            xmlPath.PartUri = element.GetPartUri();

            Dictionary <string, string> namespaces = new Dictionary <string, string>();

            StringBuilder xpath = new StringBuilder(string.Empty);

            BuildXPath(element, xpath, namespaces);

            xmlPath.XPath = xpath.ToString();

            StringBuilder nsString;

            foreach (var ns in namespaces)
            {
                nsString = new StringBuilder(string.Empty);
                nsString.Append("xmlns:");
                nsString.Append(ns.Key);
                nsString.Append("=\"");
                nsString.Append(ns.Value);
                nsString.Append("\"");
                xmlPath.NamespacesDefinitions.Add(nsString.ToString());
            }

            return(xmlPath);
        }