How to escape the character entities in XML?

I want to pass XML as a string in an XML attribute.

<activity evt="&lt;FHS&gt;
     &lt;act&gt;
         &lt;polyline penWidth=&quot;2&quot;  points=&quot;256,435 257,432 &quot;/&gt;
     &lt;/act&gt;
   &lt;/FHS&gt;" />

Here the "evt" attribute is the XML string, so escaping all the less-than, greater-than, etc characters by the appropriate character entities works fine.

The problem is I want a fragment to be interpreted as is - the character entities themselves should be treated as simple strings.

When the "evt" attribute is read and an XML is generated from it, it should look like

<FHS>
  <act>
    &lt;polyline penWidth=&quot;2&quot;  points=&quot;256,435 257,432 &quot;/&gt;
  </act>
</FHS>

Essentially, I want to escape the character entities. How is this possible?

Answers


So you need to escape the entities in the "inner" string twice. It would look like:

&amp;lt;polyline penWidth=&amp;quot;2&amp;quot;  points=&amp;quot;256,435 257,432 &amp;quot;/&amp;gt;

I must say I hope you have a good reason to do this :) The natural way of doing it would seem to be just nesting the elements, and extracting the child elements as needed.


Need Your Help

Save and Open document files in Shared folder in Windows Phone 8.1

xamarin windows-phone-8.1

In my Windows Phone 8.1 + WIndows Store 8.1 app, need to download the file and save to some shared location. Then need to open the same file so, user can select/open through suitable native/install...