I am trying to get InnerText or InnerXml of an Xml node using XmlDocument, at the same time I want to preserve & ' ".
However, even if I try InnerXml, it only preserves & but not ' and "
I would like to know the exact reason why it is happening and the solution to this problem.
e.g. Suppose I have an Xml node with text inside "'Cancel' & 'Abort'" and in retrun when I read this node with InnerXml (or InnerText), it must give me the exact same as a string output.
But when I try to do this, it returns, "'Cancel' & 'Abort'"
This means it only preserves &
Note:
<source>"&Cancel'"</source>
<target>"&Cancel'"</target>
This is something I have in my XLIFF(XML) file, so while reading this XLIFF(XML) file, I want to retrieve the text inside both the nodes as they are visible now, without any exclusive conversion or any processing.
The Problem is the XLIFf(XML) data that I have, contains both ' or " as well as ' and " and my goal is to detect these entity references as an error because we are not supposed to have that in our data.
In other words, only ' or " shall be permitted in our data.
Try using
WebUtility.HtmlEncode()method on yourInnerXMLorInnerText