我怎么能当序列跳过XML声明? [英] How can I skip xml declaration when serializing?

查看:91
本文介绍了我怎么能当序列跳过XML声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图输出,而不XML头一个xml文件像
我想:

I'm trying to output a xml file without xml head like I tried:

Type t = obj.GetType();
XmlSerializer xs=new XmlSerializer(t);
XmlWriter xw = XmlWriter.Create(@"company.xml",
                                        new XmlWriterSettings() { OmitXmlDeclaration = true, Indent = true });
xs.Serialize(xw,obj);
xw.Close();



但它仍然在xml文件中允许输出。
我不想串技巧。任何想法?

But it's still outputing in the xml file. I don't want string tricks. Any ideas?

推荐答案

ConformanceLevel 片段,就像这样:

Type t = obj.GetType();
XmlSerializer xs=new XmlSerializer(t);
XmlWriter xw = XmlWriter.Create(@"company.xml",
                              new XmlWriterSettings() { 
                                   OmitXmlDeclaration = true
                                   , ConformanceLevel = ConformanceLevel.Auto
                                   , Indent = true });
xs.Serialize(xw,obj);
xw.Close();

这篇关于我怎么能当序列跳过XML声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆