Exception: The XPath expression evaluated to unexpected type System.Xml.Linq.XAttribute
Your XPath is fine (although you might want it to be more selective), but you have to adjust how you evaluate it...
XPathSelectElement()
, as its name implies, should only be used to select elements.
XPathEvaluate()
is more general and can be used for attributes. You can enumerate over the results, or grab the first:
var type = ((IEnumerable<object>)doc.XPathEvaluate("//Employee/Address/@Type"))
.OfType<XAttribute>()
.Single()
.Value;
Another option would be:
var addresses = doc.XPathSelectElements("//Employee/Address"));
foreach(var address in addresses) {
var addrType = address.Attribute("Type").Value;
}