I get a null exception on this because MYTAG1 doesn’t exist. I understand that this is because Element(“MYTAG1”) is null and calling Elements(“MYTAG2”) on it wont work.
How do I deal with this to prevent the crash?
var myItems = from myNode in Nodes.Element("MYTAG1").Elements("MYTAG2")
select new EPTableItem
{
// Assign stuff here
};
I can’t think of a clever way to incorporate an
ifstatement into the C# query syntax, so I’ll propose the following solution which checks for the required node before executing the query.