xml structure example:
<item>
<title>Foo</title>
<description>Boo</description>
<image>Poo</image>
</item>
and my code is:
var rssFeeds =
from feed in rssXML.Descendants("item")
select new
{
Title = feed.Element("title").Value,
Description = feed.Element("description").Value,
Image= feed.Element("image").Value,
};
the question is how can I check if the “title” element exist in the code above…if not exists take some other element
You could use the explicit
XElementto string conversion (which converts a nullXElementreference to a null string reference) in conjunction with the null coalescing operator: