Removing All Namespaces from XML Using C# Linq | Linq Programmer Guide

,
Below is the simple C# linq code snippet that strips namespaces from an XML string.

public static string RemoveAllNamespaces(string xmlDocument)
{
    var xml = XElement.Parse(xmlDocument);
    xml.Descendants().Select(o => o.Name = o.Name.LocalName).ToArray();
    return xml.ToString();
}