Linq XPath, :
var document = XDocument.Load("data.xml").Root;
//Find a Department with a given value and retrieve its Employee parent
string xPath = "//Department[text() = '{0}']/parent::Employee";
//Search for "Account" Department. If nun was found will return null and then
//search for "Finance"
var employee = document.XPathSelectElement(string.Format(xPath, "Account")) ??
document.XPathSelectElement(string.Format(xPath, "Finance"));
XPath, :
var employee = (from item in XDocument.Load("data.xml").Descendants("Employee")
let department = item.Element("Department").Value
orderby department == "Account" ? 1 :
department == "Finance" ? 2 : 3
select item).FirstOrDefault();
:
var employee = (from item in XDocument.Load("data.xml").Descendants("Employee")
group item by item.Element("Department").Value into grouping
orderby grouping.Key == "Account" ? 1 :
grouping.Key == "Finance" ? 2 : 3
select grouping.ToList()).FirstOrDefault();