Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (24 sloc) 714 Bytes
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
public static class XmlExtensions
{
public static void StripNamespace(this XDocument document)
{
if (document.Root == null)
{
return;
}
foreach (var element in document.Root.DescendantsAndSelf())
{
element.Name = element.Name.LocalName;
element.ReplaceAttributes(GetAttributes(element).ToList());
}
}
static IEnumerable<XAttribute> GetAttributes(XElement xElement)
{
return xElement.Attributes()
.Where(x => !x.IsNamespaceDeclaration)
.Select(x => new XAttribute(x.Name.LocalName, x.Value));
}
}
Something went wrong with that request. Please try again.