You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The
application contains the following XML document.
<bib>
<book title=”TCP/IP Illustrated” 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 elements that are authored by Author1. Which code segment
should you insert at line 04?
A.
return doc.Element(“bib”)
.Elements()
.SelectMany(e1 => e1.Elements()
.Where(e2 => e2 .Equals(new XElement(“author”,” Author1 “))));
B.
return doc.Element(“bib”)
.Elements()
.SelectMany(e1 => e1.Elements()
.Where(e2 => (string)e2 == ” Author1 “));
C.
return doc.Element(“bib”)
.Elements()
.Where(e1 => e1.Elements().Any(e2 => (string)e2 == ” Author1 “));
D.
return doc.Element(“bib”)
.Elements()
.Where(e1=> e1.Elements().Any(e2 => e2 .Equals(new XElement(“author”,”Author1″))));