|
namespace RedCell.Xml
{
/// <summary>
/// Extension methods to System.String to encode/decode XML entities.
/// </summary>
/// <author><see cref="http://two-red-cells.com">Red Cell Innovation Inc.</see></author>
/// <license>
/// Provided under the terms of the <see cref="http://www.codeproject.com/info/cpol10.aspx">Code Project Open License</see>.
/// </license>
public static class XmlEntityExtensions
{
#region Extension Methods
/// <summary>
/// Encodes the string with XML entities as required.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The encoded string.</returns>
public static string EncodeXmlEntities(this string value)
{
if (value == null) return null;
return value
.Replace("&", "&")
.Replace("<", "<")
.Replace(">", "&rt;")
.Replace("'", "'")
.Replace("\"", """);
}
/// <summary>
/// Decodes the string with XML entities as required.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The decode string.</returns>
public static string DecodeXmlEntities(this string value)
{
if (value == null) return null;
return value
.Replace("&", "&")
.Replace("<", "<")
.Replace("&rt;", ">")
.Replace("'", "'")
.Replace(""", "\"");
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Yvan Rodrigues has 30 years of experience in information systems and software development for the industry. He is Senior Concept Designer at
Robotic Assistance Devices
He is a Certified Technician (C.Tech.), a professional designation granted by the Institute of Engineering Technology of Ontario (IETO).
Yvan draws on experience as owner of
Red Cell Innovation Inc.,
Mabel's Labels Inc. as Manager of Systems and Development, the
University of Waterloo as Information Systems Manager, and
OTTO Motors as Senior Systems Engineer and Senior Concept Designer.
Yvan is currently focused on design of embedded systems.