Geeks With Blogs
Rohit Gupta Engaging talk on Microsoft Technologies ....My Resume
var bookQuery = 

from book in bookXml.Descendants("Item")
let attributes = book.Element("ItemAttributes")

let price = Decimal.Parse((
  && book.Element("OfferSummary").Elements("LowestNewPrice").Any()
  ? book.Element("OfferSummary")
  : (attributes.Elements("ListPrice").Any()
      ? attributes.Element("ListPrice").Element("Amount").Value 
      : "0"))) / 100

select new {Price = price};

Elements(“node”).Any() does the trick.

Some other Linq tips: Some extensions to use with Linq include: Intersect, Union and Except. Intersect returns a IEnumerable collection which is a inner join between the 2 collections. Union returns a collection which is a full outer join between the 2 collections Except returns elements unique to collection1 that don’t exist in the collection2. Posted on Monday, October 13, 2008 4:33 PM | Back to top

Comments on this post: Linq To XML : Check for existence of element

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Rohit Gupta | Powered by: