You are creating an application that performs contact management. You load customer information from the following XML to an XElement object named customersRootElement:

<customers>
<customer id="7" phone="555-555-1211">
<name firstName = "Thomas" lastName = "Jensen"/>
<address street="12 Willow Way" city="Treeland" state="NJ" zip="14322" />
</customer>
<customer id="8" phone="555-555-1213">
<name firstName = "Henrick" lastName = "Jensen"/>
<address street="12 Willow Way" city="Treeland" state="NJ" zip="14322" />
</customer>
</customers>

You need to retrieve the customer element with the id 7.

Which code segment do you use?

 Posted by Rajkatie on 9/1/2012 | Category: ADO.NET Interview questions | Views: 2545 | Points: 40
Select from following answers:
  1. XElement customer = customersRootElement.Elements("customer") .Where(el => el.Attributes("id").Any(a => (string) a == "7")) .FirstOrDefault();
  2. XElement customer = xElement.Elements("customer") .Where(el => el.Attributes("id").Any(a => (string)a == "7"));
  3. XElement customer = customersRootElement.Attributes("customer") .Where(a => (string)a == "7").FirstOrDefault();
  4. All Above

Show Correct Answer


Source: MeasureUp.com | | Alert Moderator 

Comments or Responses

Login to post response