Hi,
I want to remove the attributes of all tags from a XML (I want to keep only the tags and their inner value). What's the easiest way to do this in C#?
Hi,
I want to remove the attributes of all tags from a XML (I want to keep only the tags and their inner value). What's the easiest way to do this in C#?
foreach (XmlElement el in nodes.SelectNodes(".//*")) {
el.Attributes.RemoveAll();
}
static void removeAllAttributes(XDocument doc)
{
foreach (var des in doc.Descendants())
des.RemoveAttributes();
}
Usage:
var doc = XDocument.Load(path); //Or .Parse("xml");
removeAllAttributes(doc);
string res = doc.ToString();