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#?
Remove a Text Node xml is loaded into xmlDoc. Set the variable x to be the first title element node. Set the variable y to be the text node to remove. Remove the element node by using the removeChild() method from the parent node.
In the XML Source task pane, click XML Maps. The XML Maps dialog box is displayed. Select the XML map that you want to delete. Click Delete, and then click OK.
An element with no content is said to be empty. The two forms produce identical results in XML software (Readers, Parsers, Browsers). Empty elements can have attributes.
Why should we avoid XML attributes. Attributes cannot contain multiple values but child elements can have multiple values. Attributes cannot contain tree structure but child element can. Attributes are not easily expandable.
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();
foreach (XmlElement el in nodes.SelectNodes(".//*")) {
el.Attributes.RemoveAll();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With