To Remove a Node From XML on a Condition on its attribute

Puneet20884
Posted by Puneet20884 under C# category on | Views : 3242
XmlDocument xmlDoc = new XmlDocument();
string strRootXmlPath = "";
xmlDoc.Load(strRootXmlPath);
XmlNodeList aElements = xmlDoc.SelectNodes("gallery/swf");

foreach (XmlNode node in aElements)
{
if (node.Attributes["catid"].Value == lstBannerCategories.SelectedValue)
{
node.ParentNode.RemoveChild(node);
break;
}
}
xmlDoc.Save(strRootXmlPath);

Comments or Responses

Login to post response