c# XmlDocument 输出字符串

 

            XmlDocument document = new XmlDocument();
            XmlDeclaration declaration = document.CreateXmlDeclaration("1.0", "utf-8", "yes");
            document.AppendChild(declaration);
            XmlElement element = document.CreateElement("USER");
            element.InnerText = "测试用例";
            document.AppendChild(element);

            MemoryStream stream = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(stream,Encoding.UTF8);
            writer.Formatting = Formatting.Indented;
            document.Save(writer);

            StreamReader reader = new StreamReader(stream,Encoding.UTF8);
            stream.Position = 0;
            String content = reader.ReadToEnd();
            reader.Close();
            stream.Close();

            Console.WriteLine(content);
            Console.ReadLine();

你可能感兴趣的:(Stream,String,user,C#,测试)