这是一个hack-ish的方法,而不必将整个输出字符串加载到XmlDocument中:
using System; using System.Text; using System.Xml; using System.Xml.Serialization; public class Example { public String Name { get; set; } static void Main() { Example example = new Example { Name = "Foo" }; XmlSerializer serializer = new XmlSerializer(typeof(Example)); XmlSerializerNamespaces emptyNamespace = new XmlSerializerNamespaces(); emptyNamespace.Add(String.Empty,String.Empty); StringBuilder output = new StringBuilder(); XmlWriter writer = XmlWriter.Create(output,new XmlWriterSettings { OmitXmlDeclaration = true }); serializer.Serialize(writer,example,emptyNamespace); Console.WriteLine(output.ToString()); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。