i have TextBox to take comment from user, comments will be saved into XML file the problem is when i write a text have enter key (new line ) it will save into the xml in the right way like this
<comment>
sdagsg
fag
fdhfdhgf
</comment>
but when i read from the xml looks like this " sdagsg fag fdhfdhgf"
string strXstFile = Server.MapPath(@"~/TopicAndComments.xsl");
XslCompiledTransform x = new XslCompiledTransform();
// Load the XML
XPathDocument doc = new XPathDocument(Server.MapPath(@"~/TopicAndComments.xml"));
// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(strXstFile);
MemoryStream ms = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(ms, Encoding.ASCII);
StreamReader rd = new StreamReader(ms);
//Pass Topic ID to XSL file
XsltArgumentList xslArg = new XsltArgumentList();
xslArg.AddParam("TopicID", "", HiddenField_SelectedTopicID.Value.ToString());
xslt.Transform(doc, xslArg, writer);
ms.Position = 0;
strHtml = rd.ReadToEnd();
rd.Close();
ms.Close();
There is nothing wrong with the read of the XML file. XML is not sensitive to white space.
When you want some parts in XML to not follow all the XML rules and be a bit special, you use a so-called CDATA section. This is what you should be using when "saving" the data of the user.
See one way of how to do it in C#. The way you write XML may have a different equivalent:
http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.createcdatasection.aspx
And I think I agree with Davide Piras in his comment on the question. I think you are having the same issue as Escaping new-line characters with XmlDocument, and hence picked the favorite answer to me from there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With