繁体   English   中英

从xml文件中删除版本

[英]Removing version from xml file

我正在使用XmlWriter创建一个类似Xml的格式。 但在输出中也有版本信息。

<?xml version="1.0" encoding="utf-8"?>

我的文件中不需要这个。 我怎样才能做到这一点? 有没有办法通过代码删除它?

使用ConformanceLevelOmitXmlDeclaration属性。 例:

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也有其他属性(缩进等)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM