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);
精彩评论