从xml文件中删除版本
我正在使用XmlWriter
创建一个类似Xml的格式。 但在输出中也有版本信息。
我的文件中不需要这个。 我怎样才能做到这一点? 有没有办法通过代码删除它?
使用ConformanceLevel
和OmitXmlDeclaration
属性。 例:
XmlWriter w; w.Settings = new XmlWriterSettings(); w.Settings.ConformanceLevel = ConformanceLevel.Fragment; w.Settings.OmitXmlDeclaration = true;
创建XmlWriter时,使用XmlWriterSettings传递所需的设置:
XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; writer = XmlWriter.Create(Console.Out, settings);
XmlWriterSettings也有其他属性(缩进等)。
您可以使用
XmlWriterSettings类
并使用XmlWriterSettings.OmitXmlDeclaration属性