Example #1
0
    /// <summary>
    /// Decodes an XML encoded string to its normal representation with
    /// the entities resolved (i.e. angle brackets in text).
    /// </summary>
    /// <param name="value" this="true">The value to decode in XML compatible way.</param>
    /// <returns>The decoded string.</returns>
    public static string XmlDecode(this string value)
    {
        Guard.NotNull(() => value, value);

        if (value.Length == 0)
        {
            return(value);
        }

        var output = new StringBuilder();
        var reader = XmlReader.Create(new StringReader(value), new XmlReaderSettings {
            ConformanceLevel = ConformanceLevel.Fragment
        });

        reader.MoveToContent();
        var text = (XText)XText.ReadFrom(reader);

        return(text.Value);
    }