Exemple #1
0
        /// <summary>
        /// Writes the XML nodes into the <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">the <see cref="XmlWriter"/> to use.</param>
        /// <exception cref="ArgumentNullException">if <paramref name="writer"/> is null.</exception>
        public void WriteTo(XmlWriter writer)
        {
            if (writer == null)
            {
                throw LogArgumentNullException(nameof(writer));
            }

            var streamWriter = new XmlTokenStreamWriter(_entries, _excludedElement, _excludedElementNamespace);

            streamWriter.WriteTo(writer);
        }
        /// <summary>
        /// Applies a canonicalization transform over a set of XML nodes.
        /// </summary>
        /// <param name="tokenStream">the set of XML nodes to transform.</param>
        /// <param name="includeComments">include comments in canonical bytes.</param>
        /// <param name="inclusiveNamespacesPrefixList">list of namespace prefixes to include</param>
        /// <returns>the bytes of the transformed octets.</returns>
        internal static string GetString(XmlTokenStream tokenStream, bool includeComments, string[] inclusiveNamespacesPrefixList)
        {
            var streamWriter = new XmlTokenStreamWriter(tokenStream);

            using (var stream = new MemoryStream())
                using (var writer = XmlDictionaryWriter.CreateTextWriter(Stream.Null))
                {
                    writer.StartCanonicalization(stream, includeComments, inclusiveNamespacesPrefixList);
                    streamWriter.WriteTo(writer);
                    writer.EndCanonicalization();
                    writer.Flush();
                    return(Encoding.UTF8.GetString(stream.GetBuffer(), 0, (int)stream.Length));
                }
        }