i have this simple code:
var xel=new XElement("myElement");
xel.Value="\r"; // assign carriage return
xel.Save(@"file.xml",,SaveOptions.DisableFormatting)
If i open the file with notepad++ and i show all chars, i see that the element value is saved as CR+LF.
Then, i'm not able to read the file again.
Anyone can help me? Thanks!
Edit: i found follow solution, but i' m not sure that it is the best one.
var xel = new XElement("myElement");
xel.Value = "\r";
XmlWriterSettings settings = new XmlWriterSettings();
settings.NewLineHandling=NewLineHandling.None;
settings.OmitXmlDeclaration = true;
System.Text.StringBuilder result = new System.Text.StringBuilder();
using (XmlWriter writer = XmlWriter.Create(result, settings)) {
xel.WriteTo(writer);
}
var text = result.ToString(); // expected output