tags:

views:

34

answers:

2

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#?

+1  A: 

foreach (XmlElement el in nodes.SelectNodes(".//*")) {

el.Attributes.RemoveAll();

}

Ivo
+1  A: 
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();
lasseespeholt