We'd need to see the xml; @Lee gives the correct approach here, so something like:
var el = rootElRecDocXml.SelectSingleNode(
"/ArrayOfRecentFiles/RecentFile[text()='"+mFilePath+"']");
(taking your edit/reply into account)
However! There are lots of gotchas:
- the query will be case-sensitive
- white-space will be significant (so
<foo>abc</foo>
is different to <foo> abc[newline]</foo>
etc - ditto carriage return)
- xml namespaces are significant, so you may need
.SelectSingleNode("/alias:ArrayOfRecentFiles[text()='"+mFilePath+"']", nsmgr);
, where nsmgr
is the namespace-manager
To give a complete example, that matches your comment:
XmlDocument rootElRecDocXml = new XmlDocument();
rootElRecDocXml.LoadXml(@"<ArrayOfRecentFiles> <RecentFile>C:\asd\1\Examples\8389.atc</RecentFile> <RecentFile>C:\asd\1\Examples\8385.atc</RecentFile> </ArrayOfRecentFiles>");
string mFilePath = @"C:\asd\1\Examples\8385.atc";
var el = rootElRecDocXml.SelectSingleNode(
"/ArrayOfRecentFiles/RecentFile[text()='" + mFilePath + "']");
Here, el
is not null
after the SelectSingleNode
call. It finds the node.