first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

LINQ to XML: “…use XPathEvaluate() instead of XPathSelectElement[s]()”

First, the documentation for all the XPath extension methods from LINQ to XML is already available online at http://msdn2.microsoft.com/en-us/library/system.xml.xpath.extensions_methods(VS.90).aspx

Regarding the evaluation of XPath expressions returning XAttribute, you probably want to use XPathEvaluate() instead of XPathSelectElements. XPathSelectElements() and XPathSelectElement() are specialized versions of XPathEvaluate() that return either a sequence of XElement or one XElement respectively. They are provided as properly typed convenience methods given that quering for elements is such a common task.

[http://connect.microsoft.com/VisualStudio/feedback/details/289519/xpathselectelement-s-invalidoperationexception-query-other-node-types]

mod date: 2010-03-14T02:12:37.000Z