Использование LINQ to XML ...
public static void RemoveAttributes(XNode parent, XName attribute)
{
// I'm not sure what would happen if we tried to remove the attribute
// while querying... seems like a bad idea.
var list = parent.Descendants()
.Attributes(attribute)
.ToList();
foreach (var attribute in list)
{
attribute.Remove();
}
}
Тогда:
RemoveAttributes(doc, "mlns");
RemoveAttributes(doc, "yz");
РЕДАКТИРОВАТЬ: Я только что заметил, что на самом деле это должно быть еще проще, используя метод расширения Remove
:
public static void RemoveAttributes(XNode parent, XName attribute)
{
parent.Descendants()
.Attributes(attribute)
.Remove();
}
Так что вы можете сделать это без метода довольно просто:
doc.Descendants().Attributes("mlns").Remove();
doc.Descendants().Attributes("yz").Remove();