Removing attribute from xml file in C#.

SheoNarayan
Posted by SheoNarayan under C# category on | Views : 17496
To remove attribute from xml file, you can use following code snippets.

private void RemoveAttribute()
{
XmlDocument xmlDoc = new XmlDocument();
if (File.Exists("myfile.xml"))
{
xmlDoc.Load("myfile.xml");
XmlNodeList list = xmlDoc.GetElementsByTagName("rect");
foreach (XmlNode node in list)
{
node.Attributes.RemoveNamedItem("x");
}

xmlDoc.Save(xmlFile);
}
}


Here, I am trying to remove x attribute from rect node of existing xml file.

Comments or Responses

Login to post response