I am looking on the Internet how to save carriage returns from XML data, but I could not find the answer, so I am here :)
The goal is to write the contents of the XML data to a file. So, if the node value contains some data "\ r \ n", there is a soft need to write it to a file in order to create a new line, but it is not written even with space: save.
Here is my test class:
XElement xRootNode = new XElement("DOCS"); XElement xData = null; //XNamespace ns = XNamespace.Xml; //XAttribute spacePreserve = new XAttribute(ns+"space", "preserve"); //xRootNode.Add(spacePreserve); xData = new XElement("DOC"); xData.Add(new XAttribute("FILENAME", "c:\\titi\\prout.txt")); xData.Add(new XAttribute("MODE", "APPEND")); xData.Add("Hi my name is Baptiste\r\nI'm a lazy boy"); xRootNode.Add(xData); bool result = Tools.writeToFile(xRootNode.ToString());
And here is my process class:
try { XElement xRootNode = XElement.Parse(xmlInputFiles); String filename = xRootNode.Element(xNodeDoc).Attribute(xAttributeFilename).Value.ToString(); Boolean mode = false; try { mode = xRootNode.Element(xNodeDoc).Attribute(xWriteMode).Value.ToString().ToUpper().Equals(xWriteModeAppend); } catch (Exception e) { mode = false; } String value = xRootNode.Element(xNodeDoc).Value; StreamWriter destFile = new StreamWriter(filename, mode, System.Text.Encoding.Unicode); destFile.Write(value); destFile.Close(); return true; } catch (Exception e) { return false; }
Does anyone have any ideas?
Baptx source share