I am loading the below xml using LoadXml. I need to remove the entire <site> .... </site> node based on a condition using C#.
Followed:
XmlDocument xdoc= new XmlDocument();
xdoc.LoadXml(xmlpath);
string xml = xdoc.InnerXml.ToString();
if(xml.Contains("href"+"\""+ "www.google.com" +"\"")
{
string removenode = ""; // If href=www.google.com is present in xml then remove the entire node. Here providing the entire <site> .. </site>
xml.Replace(removenode,"");
}
It is not replacing the node with null
The XML is:
<websites>
<site>
<a xmlns="http://www.w3.org/1999/xhtml" href="www.google.com"> Google </a>
</site>
<site>
<a xmlns="http://www.w3.org/1999/xhtml" href="www.hotmail.com"> Hotmail </a>
</site>
</websites>