I have a collection of MODS records that looks like this:
<modsCollection>
<mods [namespaces etc] >
<genre authority="diva" type="contentType" lang="eng">Other academic</genre>
<genre authority="diva" type="contentType" lang="swe">Övrigt vetenskapligt</genre>
<name type="personal">
<namePart type="family">Svensson</namePart>
<namePart type="given">Sven</namePart>
<namePart type="date">1880-</namePart>
<role>
<roleTerm type="code" authority="marcrelator">aut</roleTerm>
</role>
<affiliation>Stockholms universitet, institutionen institutionen</affiliation>
</name>
[...]
</mods>
<mods/>
<mods/>
</modsCollection>
My LINQ query to search the colloction for records affiliated with a certain person with a certain role looks like this:
XElement[] hits = (from record in x.Root.Elements(modsV3 + "mods").Elements(modsV3 + "name")
from r1 in record.Elements(modsV3+"namePart")
where
r1.HasAttributes &&
r1.Attribute("type").Value == "family" &&
r1.Value == familyName
from r2 in record.Elements(modsV3 + "namePart")
where
r2.HasAttributes &&
r2.Attribute("type").Value == "given" &&
r2.Value == givenName
from r3 in record.Elements(modsV3 + "role").Elements(modsV3+"roleTerm")
where
r3.HasAttributes &&
r3.Attribute("type").Value == "code" &&
r3.Value == "aut"
select r1.Parent.Parent).ToArray<XElement>();
I think this query could be better written. How?