& characters are converted to Ampersand: & after ToXmlFile or ToXml

The ampersand (&) is a reserved character in xml. When you enter data containing reserved chars into the binding classes they are automatically encoded when ToXml is called.

So the following data 

xxxx.ValidationFunction = "function test(x) { return x != null && x.test == true; }";

would produce XML like this

<ValidationFunction>function test(x) { return x != null &amp;&amp; x.test == true;}</ValidationFunction>

When the data is read back in it is unpadded, so it looks like this again.
Debug.Assert(xxxx.ValidationFunction == "function test(x) { return x != null && x.test == true; }");


One way around this is to place your data into a CDATA block.
i.e.

<![CDATA[function test(x) { return x != null && x.test == true; }]]>

You can then create XML that looks like this
<ValidationFunction><![CDATA[function test(x) { return x != null && x.test == true; }]]></ValidationFunction>

When the data is read back in it is unpadded, so it looks like this again.
Debug.Assert(xxxx.ValidationFunction == "function test(x) { return x != null && x.test == true; }");

See Also:

Add Feedback