You need to create an XmlWriter
:
using (var w = XmlWriter.Create(path, new XmlWriterSettings {
NewLineChars = "\n",
}))
{
xml.Save(w);
}
Question
I have a code section looking like this:
XDocument xml = new XDocument(
new XElement("test1",
new XElement("test2", "abc")
)
);
I now want to save the xml document using the Save method:
xml.Save("test.xml");
Then I took a look at the file using a hex editor and noticed that it has windows line endings (/r/n). However, I "only" need UNIX line endings (/n).
Thanks in advance!
Solution
You need to create an XmlWriter
:
using (var w = XmlWriter.Create(path, new XmlWriterSettings {
NewLineChars = "\n",
}))
{
xml.Save(w);
}
OTHER TIPS
var xml = "<?xml version= ..."; //your xml string
using (var w = XmlWriter.Create(path,
new XmlWriterSettings
{
NewLineChars = "\n",
})
)
{
w.WriteRaw(xml);
}