I am trying to find a node by the name attribute value.
Here is a sample of the xml document:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE kfx:XMLRELEASE SYSTEM "K000A004.dtd">
<kfx:XMLRELEASE xmlns:kfx="http://www.kofax.com/dtd/">
<kfx:KOFAXXML>
<kfx:BATCHCLASS ID="00000008" NAME="CertficateOfLiability">
<kfx:DOCUMENTS>
<kfx:DOCUMENT DOCID="00000006" DOCUMENTCLASSNAME="COL">
<kfx:DOCUMENTDATA>
<kfx:DOCUMENTFIELD NAME="Producer Name" VALUE="Howalt+McDowell Insurance" />
...
....
Here is my attempted expression:
var xml = XDocument.Load(new StreamReader("C:\\Users\\Matthew_cox\\Documents\\test.xml"));
XNamespace ns = "http://www.kofax.com/dtd/";
XmlNamespaceManager nsm = new XmlNamespaceManager(xml.CreateNavigator().NameTable);
nsm.AddNamespace("kfx", ns.NamespaceName);
var docs = xml.Descendants(ns + "DOCUMENT");
foreach(var doc in docs)
{
doc.XPathSelectElement("/DOCUMENTDATA/DOCUMENTFIELD/[@name='Producer Name']", nsm); //this line produces this exception: Expression must evaluate to a node-set.
}