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 Function GetBooks(xml As String) As IEnumerable(Of XElement)
02 Dim doc As XDocument = XDocument.Parse(xml)
03
04 End Function
You need to return a list of book XML elements that are authored by Author1. Which code segment
should you insert at line 03?
A.
Return Document.Element(“bib”)
.Elements() .SelectMany(Function(e1 As) e1.Elements()
.Where(Function(e2 As) e2.Equals(New XElement(“author”, “Author1”))))
B.
Return Document.Element(“bib”)
.Elements().SelectMany(Function(e1 As) e1.Elements()
.Where(Function(e2 As) DirectCast(e2, String) = “Author1”))
C.
Return Document.Element(“bib”)
.Elements()
.Where(Function(e1 As) e1.Elements().Any(Function(e2 As) DirectCast(e2, String) = “Author1”))
D.
Return Document.Element(“bib”)
.Elements()
.Where(Function(e1 As) e1.Elements().Any(Function(e2 As) e2.Equals(New XElement(“author”,
“Author1”))))