开发者

exclude xml declaration while saving

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜