<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
I have a web.config file which contains xmlns in configuration tag.
I want to delete a specific node. but I am not able to read this file.
Below is the code :
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(PATH + WEB_CONFIG_PATH);
//XmlNode t = xmlDoc.SelectSingleNode("/system.webServer/handlers /add[@path='Reserved.ReportViewerWebControl.axd']");
XmlNode t = xmlDoc.SelectSingleNode("/configuration/system.webServer");
if (t != null)
{
t.ParentNode.RemoveChild(t);
xmlDoc.Save(PATH + WEB_CONFIG_PATH);
}
If I remove xmlns from configuration tag this code works fine.
please provide some solution so that this code can work if xmlns is present.
You need to add support for the XML namespace by adding a
XmlNamespaceManagerto your code, and using it on theSelectSingleNodecall. Also, you need to tweak the XPath for your call to include XML namespace prefixes: