Skip to content

Instantly share code, notes, and snippets.

@einaros
Created October 29, 2010 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save einaros/653306 to your computer and use it in GitHub Desktop.
Save einaros/653306 to your computer and use it in GitHub Desktop.
string xml = @"
<root xmlns='http://www.w3.org/TR/html4/' xmlns:h='http://www.w3.org/TR/html4/' xmlns:f='http://www.w3schools.com/furniture'>
<h:table><h:tr><h:td>Apples</h:td><h:td>Bananas</h:td></h:tr></h:table><f:table><f:name>African Coffee Table</f:name>
<f:width>80</f:width><f:length>120</f:length></f:table></root>";
XElement x = XElement.Parse(xml);
(from node in x.DescendantsAndSelf()
where node is XElement
from attr in node.Attributes()
where attr.IsNamespaceDeclaration && attr.Name.LocalName == "xmlns"
select attr).All(attr => { attr.Remove(); return true; });
Console.Out.WriteLine(x.ToString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment