C# – XPathException in XmlDocument.SelectNodes

Hi guys.

I currently have some trouble with XmlNodeList.

I get a XPath.XPathException and he tells me that it needs to receive a list of nodes.

he's able to read the xmlDocument (i checked while debug), but he's not able to get the nodeList

My reading code looks like this:

 XmlDocument doc = new XmlDocument(); doc.Load(path + @"\employees.xml"); XmlNodeList nodeList = doc.SelectNodes("employees/[@name='employee']"); foreach (XmlNode node in nodeList) { Console.WriteLine(node.Attributes["firstname"].Value); } 

my .xml file looks something like this:

 <employees> <employee> <firstname>John</firstname> <lastname>Doe</lastname> </employee> <employee> <firstname>Jenny</firstname> <lastname>Doe</lastname> </employee> </employees> 

I'm a bit stuck. would be cool if you guys could help me a little. Thanks 🙂

by Jonas_Dralle via /r/csharp

Leave a Reply