Get attribute value from C # / xpath
Use this XPath:
/configuration/log4net/appender/param[@name='File']/@value Depending on how you read the XML, the use of XPath may be slightly different. If you use XDocument , you can use the XPathSelectElement extension XPathSelectElement . If you are using an XmlDocument , there is a SelectSingleNode method. And if you are using XPathDocument , you need to compile XPathExpression and use it against the navigator.
You can use XmlDocument . See XmlNode.SelectSingleNode and others.
Example:
XmlDocument doc = new XmlDocument(); doc.LoadXml(@"<configuration> <log4net> <appender> <param name=""File"" value=""C:\""/> </appender> </log4net> </configuration>"); var node = doc.DocumentElement.SelectSingleNode("//param[@name = 'File']/@value"); Console.WriteLine(node.Value); You can use XmlDocument and SelectSingleNode method - http://msdn.microsoft.com/en-us/library/fb63z0tw.aspx
It will find the node matching your XPath.
I would do it with LINQ to XML (not with XPath)