I have a simple XML doc with no Namespace
Here is the code I wrote in C# to search for a particular element based on Name.
public XmlElement SearchXML(string name)
{
XmlDocument xDoc = new XmlDocument();
string filePath = ConfigurationManager.AppSettings["path"];
xDoc.Load(filePath);
string xQryStr = "//NewPatient[Name='" + name + "']";
xDoc.SelectNodes(xQryStr);
XmlElement xmlEle = xDoc.DocumentElement;
return xmlEle;
}
The XML document is as follows

When I try to call the method SearchXML and pass Dennis as the arguement, instead of returning the xml element containing only the specific elements, it returns the entire document.
Where am I possibly erring?
Any help appreciated.
If you want to select a list of nodes based on an XPath expression, you need to use
.SelectNodesin this fashion:The call to
.SelectNodes(xpath)returns a list of matching XML nodes (see the MSDN documentation onXmlDocument.SelectNodes) – once you have that list, you can iterate over the matched nodes and do something with them….Or if you’re expecting only a single XML node to match your XPath expression, you can use
.SelectSingleNode, too: