How to escape the character entities in XML?

Posted by Chetan Vaity on Stack Overflow See other posts from Stack Overflow or by Chetan Vaity
Published on 2010-03-31T14:00:44Z Indexed on 2010/03/31 14:03 UTC
Read the original article Hit count: 486

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about escape-character