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