Tuesday, 4 March 2014

XML document Escape characters

Escapes or unescapes an XML file removing traces of offending characters that could be wrongfully interpreted as markup.
The following characters are reserved in XML and must be replaced with their corresponding XML entities:
  1. ' is replaced with '
  2. " is replaced with "
  3. & is replaced with &
  4. < is replaced with &lt;
  5. > is replaced with &gt;
Original CharacterXML entity replacementXML numeric replacement
<                              &lt;                                    &#60;                                    
>                              &gt;                                   &#62;                                    
"                               &quot;                               &#34;                                    
&                              &amp;                               &#38;                                    
'                               &apos;                               &#39;                                    

Examples:-
DataXml TypeIn XML
He said "OK"AttributeattributeName="He said &quot;OK&quot;"
She said "You're right"AttributeattributeName="She said &quot;You&apos;re right&quot;"
Smith&SonsAttributeattributeName="Smith&amp;Sons"
if (age > 3 && age < 8)Element<MyElement>if (age &gt; 3 &amp;&amp; age &lt; 8)</MyElement>
An XML Comment End with -->Comment<!-- An XML Comment End with --&gt; -->
A & BComment<!-- A &amp; B -->

No comments:

Post a Comment