Click here to Skip to main content
15,895,423 members
Articles / Web Development / HTML

Make your Page Social with the Open Graph Protocol

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
28 Oct 2011CPOL3 min read 39K   1.4K   24  
The Open Graph protocol specifies additional meta tags that can be added to the page to supplement social networking sites with more information about your page.
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("&", "&amp;")
                .Replace("<", "&lt;")
                .Replace(">", "&rt;")
                .Replace("'", "&apos;")
                .Replace("\"", "&quot;");
        }

        /// <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("&amp;", "&")
                .Replace("&lt;", "<")
                .Replace("&rt;", ">")
                .Replace("&apos;", "'")
                .Replace("&quot;", "\"");
        }
        #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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer Robotic Assistance Devices / AITX
Canada Canada
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.

Comments and Discussions