I\'m trying to call the XElement.XPathSelectElements() overload that requires an IXmlNamespaceResolver object. Can anyone show me how to get (or make) an IXmlNamespaceResolv
You can use an XmlNamespaceManager that implements that interface
Use the constructor which takes an XmlNameTable
, passing into it an instance of System.Xml.NameTable via new NameTable()
. You can then call AddNamespace
function to add namespaces:
var nsMgr = new XmlNamespaceManager(new NameTable());
nsMgr.AddNamespace("ex", "urn:example.org");
nsMgr.AddNamespace("t", "urn:test.org");
doc.XPathSelectElements("/ex:path/ex:to/t:element", nsMgr);