Example #1
0
        /// <summary>
        /// Initializes a new instance of the XmlPath.
        /// </summary>
        internal XmlPath(OpenXmlElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            PartUri = element.GetPartUri();

            XPath = TryBuildXPath(GetElements(element), out var namespaces);

#pragma warning disable CS0618 // Type or member is obsolete
            if (namespaces == null)
            {
                Namespaces            = ReadOnlyWrapper.Instance;
                NamespacesDefinitions = Cached.Array <string>();
            }
            else
            {
                NamespacesDefinitions = namespaces
                                        .GetNamespacesInScope(XmlNamespaceScope.Local)
                                        .Select(ns => $"xmlns:{ns.Key}=\"{ns.Value}\"")
                                        .ToArray();
                Namespaces = new ReadOnlyWrapper(namespaces);
            }
#pragma warning restore CS0618 // Type or member is obsolete
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the XmlPath from the specified OpenXmlPart.
        /// </summary>
        /// <param name="part">The OpenXmlPart.</param>
        internal XmlPath(OpenXmlPart part)
        {
            if (part is null)
            {
                throw new ArgumentNullException(nameof(part));
            }

            PartUri = part.Uri;
            XPath   = string.Empty;

#pragma warning disable CS0618 // Type or member is obsolete
            Namespaces            = ReadOnlyWrapper.Instance;
            NamespacesDefinitions = Cached.Array <string>();
#pragma warning restore CS0618 // Type or member is obsolete
        }