0

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>&quot;&amp;Cancel&apos;&quot;</source>
<target>&quot;&amp;Cancel&apos;&quot;</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 &apos; and &quot; 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.

Indigo
  • 2,887
  • 11
  • 52
  • 83

1 Answers1

-1

Try using WebUtility.HtmlEncode() method on your InnerXML or InnerText

NaYaN
  • 1,300
  • 7
  • 11
  • I think, I wasn't so clear in my question. I want to get what is inside the Xml node exactly as it is, not to change it. If there are XML entity references then it should show or return it, otherwise I do not want to explicitly change it to one. – Indigo Aug 07 '13 at 13:25
  • As per the docs, To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character (') may be represented as "'", and the double-quote character (") as """. So when you put this inside xml, it gets converted. So you have to manually convert it again, after you extract the text. Try opening your xml file on your browser, and you will observe what I mean – NaYaN Aug 07 '13 at 13:44
  • I understand what you are saying. I must apologize for the confusion and not clearly explaining what is in my XLIFF data files. Please check my updated question. Thanks. The Problem is that the XLIFf(XML) data I have contains both ' or " and ' and " and my goal is to detect these entity references as an error because we are not supposed to have that in our data. So that is why I have been asking for a sophisticated method rather than exclusively checking and converting them myself. – Indigo Aug 07 '13 at 14:21