So I have this code:
List prices = (from item in xmlDoc.Descendants(shop.DescendantXName) select new PriceDet
Before you make the cast you can check for the type using a code like this:
XElement e = item as XElement; XAttribute a = item as XAttribute; if(e != null) //item is of type XElement else //item is of type XAttribute