从XmlSerializer的编码删除 [英] remove encoding from xmlserializer
本文介绍了从XmlSerializer的编码删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的代码创建一个XML文件 -
I am using the following code to create an xml document -
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
new XmlSerializer(typeof(docket)).Serialize(Console.Out, i, ns);
这部作品在没有命名空间属性创建XML文件很大。我想也有根元素没有编码属性,但我无法找到一个方法来做到这一点。没有人有任何想法,如果可以做到这一点?
this works great in creating the xml file with no namespace attributes. i would like to also have no encoding attribute in the root element, but I cannot find a way to do it. Does anyone have any idea if this can be done?
感谢
推荐答案
旧的答案移除并用新的解决方案的更新:
假设它的确定完全地消除XML声明,因为它使没有太大意义没有编码属性:
Assuming that it's ok to remove the xml declaration completly, because it makes not much sense without the encoding attribute:
XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", "");
using (XmlWriter writer = XmlWriter.Create(Console.Out, new XmlWriterSettings { OmitXmlDeclaration = true}))
{
new XmlSerializer(typeof (SomeType)).Serialize(writer, new SomeType(), ns);
}
这篇关于从XmlSerializer的编码删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文