I am trying to query this very complicated XML document using xDocument and LINQ to XML. I want to perform the following action:
Get all elements that answer to a certain criteria, and if they don't, return another attribute from the xDocument.
Example:
<cars>
<car>
<patrol type="oil">
<url> http://Toyotaoil.com </url>
</patrol>
</car>
<car>
<patrol type="oil">
<url> http://BMWoil.com </url>
</patrol>
<patrol type="gas">
<url> http://BMWgas.com </url>
</patrol>
</car>
<car>
<patrol type="gas">
<url> http://Hondagas.com </url>
</patrol>
</car>
Now what I'd like to get from this query is a list of patrols of type oil, unless the car doesn't use petrol, and then I'd be satisfied with gas.
If I use the where
clause I just miss the cases where the car uses gas. Is there any such thing like a where
clause, where I can specify what to do if they condition wasn't met?