Ejemplo n.º 1
0
        /// <summary>
        /// Gets the included XML reader based on the current node.
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerable <XmlReader> CreateIncludedReaders()
        {
            // Grab the @href element and make sure we have it.
            string href = GetAttribute("href");

            if (href == null)
            {
                throw new ApplicationException(
                          "Cannot locate href attribute from the XInclude tag.");
            }

            // Figure out the base URI for the current reader.
            Uri baseUri = NormalizedBaseUri;

            // Figure out the URI for the new one and use that to create an
            // XML stream.
            var       newUri        = new Uri(baseUri, href);
            XmlReader reader        = Create(newUri.ToString());
            var       includeReader = new XIncludeReader(reader);

            // Check to see if we have an XPointer element.
            string xpointerAttribute = GetAttribute("xpointer");

            if (!string.IsNullOrEmpty(xpointerAttribute))
            {
                // Parse the XPointer from this.
                var xpointer = new XPointerInfo(xpointerAttribute);

                if (xpointer.IsValid)
                {
                    // Wrap the above reader in an XPath document and pull out
                    // the nodes.
                    XPathNodeIterator nodes = xpointer.SelectFrom(includeReader);

                    // Create a list of readers from the given nodes.
                    var includedReaders = new List <XmlReader>();

                    while (nodes.MoveNext())
                    {
                        XPathNavigator node = nodes.Current;

                        if (node != null)
                        {
                            XmlReader nodeReader = node.ReadSubtree();

                            includedReaders.Add(nodeReader);
                        }
                    }

                    // Return the resulting readers.
                    return(includedReaders);
                }
            }

            // Return the resulting reader.
            return(new[]
            {
                includeReader
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the included XML reader based on the current node.
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerable<XmlReader> CreateIncludedReaders()
        {
            // Grab the @href element and make sure we have it.
            string href = GetAttribute("href");

            if (href == null)
            {
                throw new ApplicationException(
                    "Cannot locate href attribute from the XInclude tag.");
            }

            // Figure out the base URI for the current reader.
            Uri baseUri = NormalizedBaseUri;

            // Figure out the URI for the new one and use that to create an
            // XML stream.
            var newUri = new Uri(baseUri, href);
            XmlReader reader = Create(newUri.ToString());
            var includeReader = new XIncludeReader(reader);

            // Check to see if we have an XPointer element.
            string xpointerAttribute = GetAttribute("xpointer");

            if (!string.IsNullOrEmpty(xpointerAttribute))
            {
                // Parse the XPointer from this.
                var xpointer = new XPointerInfo(xpointerAttribute);

                if (xpointer.IsValid)
                {
                    // Wrap the above reader in an XPath document and pull out
                    // the nodes.
                    XPathNodeIterator nodes = xpointer.SelectFrom(includeReader);

                    // Create a list of readers from the given nodes.
                    var includedReaders = new List<XmlReader>();

                    while (nodes.MoveNext())
                    {
                        XPathNavigator node = nodes.Current;

                        if (node != null)
                        {
                            XmlReader nodeReader = node.ReadSubtree();

                            includedReaders.Add(nodeReader);
                        }
                    }

                    // Return the resulting readers.
                    return includedReaders;
                }
            }

            // Return the resulting reader.
            return new[]
            {
                includeReader
            };
        }