You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
The application contains the following XML document:
<bib>
<book title=”TCP/IP Illusrated” year=”1994″>
<author>Author1</author>
</book>
<book title=”Programming in UNIX” year=”1992″>
<author>Author1</author>
<author>Author2</author>
<author>Author3</author>
</book>
<book title=”Data on the web” year=”2000″>
<author>Author4</author>
<author>Author3</author>
</book>
</bib>
You add the following code fragment. (Line numbers are included for reference only.)
01 public IEnumerable<XElement> GetBooks(string xml)
02 {
03 XDocument doc = XDocument.Parse(xml);
04 …
05 }
You need to return a list of book XML element that are authored by Author1. Which code segment should you insert at line 04?
A.
return doc.Element(“bib”).Elements()
.SelectMany(el => el.Elements()
.Where(e2 => e2.Equals(new XElement(“author”, “Author1”))));
B.
return doc.Element(“bib”).Elements()
.SelectMany(el => el.Elements()
.Where(e2 => (string)e2 == “Author1”));
C.
return doc.Elements(“bib”).Elements()
.Where(e1 => e1.Elements().Any(e2 => (string)e2 == “Author1”));
D.
return doc.Elements(“bib”).Elements()
.Where(e1 => e1.Elements().Any(e2 => e2.Equals(new XElement(“author”, “Author1”))));