Removing version from xml file

我只是一个虾纸丫 提交于 2019-11-28 02:51:49

问题


I am creating a Xml like format using XmlWriter. But in the output there is version information also.

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

I don't need this in my file. How can I do that? Is there any way to remove it by code?


回答1:


Use the ConformanceLevel and OmitXmlDeclaration properties. Example:

XmlWriter w;
w.Settings = new XmlWriterSettings();
w.Settings.ConformanceLevel = ConformanceLevel.Fragment;
w.Settings.OmitXmlDeclaration = true;



回答2:


When creating your XmlWriter, pass through the settings you want using XmlWriterSettings:

XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;

writer = XmlWriter.Create(Console.Out, settings);

XmlWriterSettings has other properties as well (indent and more).




回答3:


You can use

XmlWriterSettings class

and use XmlWriterSettings.OmitXmlDeclaration Property



来源:https://stackoverflow.com/questions/1980187/removing-version-from-xml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!