Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

use & symbole in xml as a text using c#

public static string EscapeXml( this string s )
{
  string toxml = s;
  if ( !string.IsNullOrEmpty( toxml ) )
  {
    // replace literal values with entities
    toxml = toxml.Replace( "&", "&" );
    toxml = toxml.Replace( "'", "'" );
    toxml = toxml.Replace( """, """ );
    toxml = toxml.Replace( ">", ">" );
    toxml = toxml.Replace( "<", "<" );
  }
  return toxml;
}

public static string UnescapeXml( this string s )
{
  string unxml = s;
  if ( !string.IsNullOrEmpty( unxml ) )
  {
    // replace entities with literal values
    unxml = unxml.Replace( "'", "'" );
    unxml = unxml.Replace( """, """ );
    unxml = unxml.Replace( ">", ">" );
    unxml = unxml.Replace( "<", "<" );
    unxml = unxml.Replace( "&", "&" );
  }
  return unxml;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #symbole #xml #text
ADD COMMENT
Topic
Name
3+4 =