Skip to content

Instantly share code, notes, and snippets.

@volodymyrsmirnov
Last active August 29, 2015 14:06
Show Gist options
  • Save volodymyrsmirnov/ef9009943923839aed23 to your computer and use it in GitHub Desktop.
Save volodymyrsmirnov/ef9009943923839aed23 to your computer and use it in GitHub Desktop.
public static XElement RemoveAllNamespaces(XElement e)
{
return new XElement(e.Name.LocalName, (
from n in e.Nodes()
select((n is XElement) ? RemoveAllNamespaces(n as XElement) : n)),
(e.HasAttributes) ? (from a in e.Attributes()
where (e.Attributes().Where(ah => a.Name != a.Name.LocalName && ah.Name == a.Name.LocalName).Count() == 0)
select new XAttribute(a.Name.LocalName, a.Value)) : null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment