c# - Linq to XML - Searching for Existence of a Deep Element -


i want check see if element exists in xml file. element few levels deep. following code works fine, shortest syntax can come with. can think of way more fluently without resorting classic xpath syntax?

        //create simple sample xml         xdocument doc = new xdocument(         new xdeclaration("1.0", "utf-8", "yes"),         new xelement("bookstore",             new xattribute("name", "mybookstore"),             new xelement("books",                 new xelement("book",                     new xattribute("title", "mybook"),                     new xattribute("isbn", "1234")))));          //write out boolean indicating if book exists         console.writeline(             doc.element("bookstore") != null &&             doc.element("bookstore").element("books") != null &&             doc.element("bookstore").element("books").element("book") != null         ); 

console.writeline(doc.root.descendants("book").any()); 

Comments