how to remove an attribute from a System.Xml.XmlNode object in C #. The code I tried does not work. It throws an exception "the node to be deleted is invalid child node"
foreach (XmlNode distribution
in responseXml.SelectNodes("/Distributions/Distribution/DistributionID"))
{
XmlAttribute attribute = null;
foreach (XmlAttribute attri in distribution.Attributes)
{
if (attri.Name == "GrossRevenue")
attribute = attri;
}
if (attribute != null)
distribution.ParentNode.RemoveChild(attribute);
}
source
share