开发者

exclude xml declaration while saving

开发者 https://www.devze.com 2022-12-19 06:47 出处:网络
i am generating an xml file using XDocument. when i save 开发者_运维问答this file it adds <?xml version=\"1.0\" encoding=\"utf-8\"?>

i am generating an xml file using XDocument. when i save 开发者_运维问答this file it adds

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

at the top of xml..

i want to exclude this before saving

how can i do that.


Using the save method to a XmlWriter http://msdn.microsoft.com/en-us/library/bb336977.aspx, and creating this XmlWiter with XmlWriterSettings http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.settings.aspx

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


XmlWriter writer = XmlWriter.Create(yourstream, settings);

yourXDocument.Save(writer);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号