public void SingleFullTag()
        {
            // Arrange
            const string xml = "<a>a</a>";

            // Act
            var settings = new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
            };
            var stringWriter = new StringWriter();

            using (var stringReader = new StringReader(xml))
            {
                using (XmlReader xmlReader = XmlReader.Create(stringReader))
                {
                    using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings))
                    {
                        using (var identityWriter = new XmlIdentityWriter(xmlWriter))
                        {
                            identityWriter.Load(xmlReader);
                        }
                    }
                }
            }

            // Assert
            string actual = stringWriter.ToString();

            Assert.AreEqual(xml, actual);
        }
예제 #2
0
        /// <summary>
        /// Writes the XML results.
        /// </summary>
        /// <param name="xml">The input XML.</param>
        /// <returns>The resulting XML from an identity write.</returns>
        private static string WriteXmlResults(string xml)
        {
            // Set up the XML writing to produce consistent results.
            var writerSettings = new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
            };
            var stringWriter = new StringWriter();

            // Set up the reader by chaining into the include reader.
            using (var stringReader = new StringReader(xml))
            {
                using (XmlReader xmlReader = XmlReader.Create(stringReader))
                {
                    using (var includeReader = new TestXIncludeReader(xmlReader))
                    {
                        // Set up the identity writer so we can verify the results
                        // using string.
                        using (
                            XmlWriter xmlWriter = XmlWriter.Create(stringWriter, writerSettings))
                        {
                            using (var identityWriter = new XmlIdentityWriter(xmlWriter))
                            {
                                identityWriter.Load(includeReader);
                            }
                        }
                    }
                }
            }

            // Pull out the resulting string.
            string results = stringWriter.ToString();

            // Report the input and output.
            Console.WriteLine(" Input XML: " + xml);
            Console.WriteLine("Output XML: " + results);

            // Return the results.
            return results;
        }