PrepAway - Latest Free Exam Questions & Answers

You need to create a query that generates the new XML result

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application. A
file named books.xml contains the following XML.
<bib>
<book title=”Programming in Unix” year=”1992″>
<author>Author1</author>
<author>Author2</author>
<author> Author 3 </author>
</book>
</bib>
The application must generate an XML result that contains an XML element named BookTitle for
each book.
The text content of the element must contain the title of the book.
You need to create a query that generates the new XML result. What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
XDocument document = XDocument.Load(“books.xml”);
var query = from node in document.Descendants()
where node.Name.LocalName == “book”
select new XElement(“BookTitle”, node.FirstAttribute.Value);

B.
XDocument document = XDocument.Load(“books.xml”);
var query = from node in document.DescendantNodes()

where node.ToString() == “book”
select new XText(“BookTitle” + node.ToString());

C.
XDocument document = XDocument.Load(“books.xml”);
var query = from node in document.Descendants()
where node.Name.LocalName == “book”
select new XElement(“BookTitle”).Value = node.FirstAttribute.Value;

D.
XDocument document = XDocument.Load(“books.xml”);
var query = from node in document.DescendantNodes()
where node.ToString() == “book”
select new XElement(“BookTitle”, node.ToString());


Leave a Reply