Ejemplo n.º 1
0
        public void TestDocUnformatted()
        {
            string docText = @"<doc
				><some
				one=""abc""
				two='123' 
				/></doc
				>"                ;

            XmlLightDocument doc = new XmlLightDocument(docText);

            string     content;
            TextWriter sw = new StringWriter();

            doc.WriteUnformatted(sw);
            content = sw.ToString();
            Assert.AreEqual(docText, content);

            using (MemoryStream ms = new MemoryStream())
            {
                sw = new StreamWriter(ms);
                doc.WriteUnformatted(sw);

                sw.Flush();
                ms.Position = 0;
                StreamReader sr = new StreamReader(ms);
                content = sr.ReadToEnd();
                Assert.AreEqual(docText, content);
            }
        }
Ejemplo n.º 2
0
        private string RewriteDocument(XmlLightDocument document)
        {
            using (StringWriter sw = new StringWriter())
            {
                if (Reformat)
                {
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.OmitXmlDeclaration = true;
                    settings.Indent             = IndentChars.Length > 0;
                    settings.IndentChars        = IndentChars;
                    settings.NewLineChars       = settings.Indent ? Environment.NewLine : "";
                    settings.NewLineHandling    = NewLineHandling.None;
                    settings.Encoding           = Encoding.UTF8;
                    settings.CloseOutput        = false;
                    settings.CheckCharacters    = false;

                    using (XmlWriter xw = XmlWriter.Create(sw, settings))
                        document.WriteXml(xw);
                }
                else
                {
                    document.WriteUnformatted(sw);
                }
                return(sw.ToString().Trim());
            }
        }