How to query nested XML Elements with Linq

I am just trying to convert my XML node-select statements to Linq. Now I am stuck because I am having problems with the nested structure of my XML document.

I my program I need to query an export from a commercial program named 'Endnote' (which is used for registering scientific articles).

The structure is (partly)
      <ref-type name="Journal Article">17</ref-type>
            <style face="normal" font="default" size="100%">Thuiller, W.</style>
          <style face="normal" font="default" size="100%">Patterns and uncertainties of species&apos; range shifts under clmate change</style>
          <style face="normal" font="default" size="100%">Global Change Biology</style>
      ... rest of nodes ...
  ... rest of records ...

I tried successfully selecting records havind a specific recordnumber with:
            XElement test = XElement.Load("EndnoteExport.xml");

           var records = from record in test.Descendants("record")
                          where record.Element("rec-number").Value.Equals(someValue)
                          select record;

But how can I select all records from a specific author for example?

Thanks for any help!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gautham JanardhanCommented:
var records = from record in test.Descendants("record")
                              where record.Element("Authors").Element("author").Value.Equals(somevalue)
                              select record;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
biksenbeverAuthor Commented:
Thank you very much, that looks really easy!

It first tried it and it did not work because I got an 'object not set to an instance' error.
Later on I saw that for some records the elements are optional.
So I added to the where clause:
where (record.Element("someElementName") != null) && 


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.