How to fetch XML data with 'select single node'?

I want to fetch the highlighted field in the image.

On selectSingleNode's xpath, how do I define a name space?


Keep up to date on this post and subscribe to comments

October 30, 2019 - 4:09am

Provide namespace values in xpath string only.

November 5, 2019 - 9:30pm
Response to Jayachandra Reddy K

I already tried, and it says that the name space is not defined.

November 6, 2019 - 12:34am

Try with below code.

var xmlDoc = new XmlDocument();
var namespaceName = "ns";
var namespacePrefix = string.Empty;
XmlNamespaceManager nameSpaceManager = null;
XmlNodeList nodeList = xmlDoc.SelectNodes(string.Format("/{0}fileresponse/{0}data/{0}folder/{0}pages", namespacePrefix), nameSpaceManager);
if (nodeList != null)
foreach (XmlNode childNode in nodeList)
string first = childNode.ChildNodes[0].ChildNodes[1].ChildNodes[1].InnerText;

below is sample xml:

  <NS1:Page xmlns:NS1="">


November 13, 2019 - 10:24pm
Response to Jayachandra Reddy K

Hi Jayachandra,

Thanks for the work-around I'll check and confirm.
I was just wondering why can't I use 'select single node' method since xpath can handle namespaces as well. Could it be a limitation of the method?