Wich code segment should you use?

You are implementing an ASP.NET web application.The application defines the following classes.
public class Person
{
public String Name{get; set;}
publicIList<Address> Addresses{get;set;}
}
public class Address
{
public String AddressType{get; set;}
public string AddressValue{get;set;}
}
The applicaction must generate XML from personList, wich is a collection of Person instances.The
following XML is an example of the schema than the generated XML must use.
<Persons>
<Person Name=”John Doe”>
<Address Email=”[email protected]”/>
<Address AlternativeEmail=”[email protected]”/>
<Address MSNInstanceMessenger=”[email protected]”/>
</Person>

…..
</Persons>
You need to generate the XML. Wich code segment should you use?

You are implementing an ASP.NET web application.The application defines the following classes.
public class Person
{
public String Name{get; set;}
publicIList<Address> Addresses{get;set;}
}
public class Address
{
public String AddressType{get; set;}
public string AddressValue{get;set;}
}
The applicaction must generate XML from personList, wich is a collection of Person instances.The
following XML is an example of the schema than the generated XML must use.
<Persons>
<Person Name=”John Doe”>
<Address Email=”[email protected]”/>
<Address AlternativeEmail=”[email protected]”/>
<Address MSNInstanceMessenger=”[email protected]”/>
</Person>

…..
</Persons>
You need to generate the XML. Wich code segment should you use?

A.
var XML= new XElement(“Persons”,
from person in personList
Select (new XElement(“Persons”,
newXElement(“Name”, person.Name),
from addr in person.Addresses
select new XElement(“Address”,
newXElement(addr.AddressType,
addr.AddressValue)))));

B.
var XML= new XAttribute(“Persons”,
from person in personList
Select (new XElement(“Persons”,
newXAttribute(“Name”, person.Name),
from addr in person.Addresses
select new XAttribute(“Address”,
newXAttribute(addr.AddressType,
addr.AddressValue)))));

C.
var XML= new XElement(“Persons”,
from person in personList
Select (new XElement(“Persons”,
newXAttribute(“Name”, person.Name))));

D.
var XML= new XElement(“Persons”,
from person in personList
Select (new XElement(“Person”,
newXAttribute(“Name”, person.Name),
from addr in person.Addresses
select new XElement(“Address”,
newXAttribute(addr.AddressType,
addr.AddressValue)))));



Leave a Reply 0

Your email address will not be published. Required fields are marked *