I want to remove some tags from an xml. I'm using selectNodes() but I need to pass the namespace. So I tried to get the namespace by using GetXmlNamespaces(). some of the namespaces do not have a key value. And I can not provide the namespace as a hard coded value and need to change the namespace regularly. The only values I can pass are the tag name and the file. Is there anyway I can get the namespace a tag belongs to in c#?
for example I'm passing this namespace as a hardcoded value but I need to do it programmatically.
var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("a", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
XmlNodeList nodes = doc.SelectNodes("//a:workbook/a:fileVersion", nsmgr);
this namespace 'xmlns="http://schemas.openxmlformats.org/package/2006/relationships"' does not have a key when I try to get it by using
IDictionary<string, string> nameSpaces = GetXmlNamespaces(xmlFilePath);