How do I have LINQ to XML iqnore all namespaces? Or alteranately, how to I strip out the namespaces?
I\'m asking because the namespaces are being set in a semi-rando
As I found this question in search for an easy way to ignore namespaces on attributes, here's an extension for ignoring namespaces when accessing an attribute, based on Pavel´s answer (for easier copying, I included his extension):
public static XAttribute AttributeAnyNS(this T source, string localName)
where T : XElement
{
return source.Attributes().SingleOrDefault(e => e.Name.LocalName == localName);
}
public static IEnumerable ElementsAnyNS(this IEnumerable source, string localName)
where T : XContainer
{
return source.Elements().Where(e => e.Name.LocalName == localName);
}