Question

My XML file has some french characters.

<fr>Non prêt pour recevoir l&apos;échantillon.</fr>

After XElement::Load() and then save it without any change. it becomes

<fr>Non prêt pour recevoir l'échantillon.</fr>

How did this happen and how to solve it?

Was it helpful?

Solution

AFAIK the only characters required escape sequences for tag content are &, < and >. Thus XElement produces valid XML.

If your code requires this escape to persist it's, probably, not very good, since it's requires non-standard behaviour.

But if you wish to preserve exact content you can use a CDATA section.

As for your comment, I guess it's not possible to use CDATA if you not in control of incoming XML. Possibly you only option then is to either process XML as a text file, or to replace ' to &apos; (and other escape sequences) after XML modification, after converting it to a string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top