Exclude xml declaration when saving

I am creating an xml file using an 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 this.

+3
source share
1 answer

Using the save method in XmlWriter http://msdn.microsoft.com/en-us/library/bb336977.aspx and create this XmlWiter using 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);
+4
source

Source: https://habr.com/ru/post/1730867/


All Articles