I am trying to get link to convert data into XML. The LINQ expression i have almost working is:
XElement xml = new XElement("contacts",
lstEmailData.Select(i => new XElement("Data",
new XAttribute("URL", i.WebPage ),
new XAttribute("emails", i.Emails.ToArray() + " , ")
)));
where lstEmailData is defined as:
List<PageEmail> lstEmailData = new List<PageEmail>();
lstEmailData.Add(new PageEmail("site2", new List<string>() {
"MyHotMail@NyTimes.com", "contact_us@ml.com" }));
where PageEmail is:
class PageEmail
{
public string WebPage { get; set; }
public List<string> Emails { get; set; }
public PageEmail(string CurWebPage, List<string> CurEmails)
{
this.WebPage = CurWebPage;
this.Emails = CurEmails;
}
}
the XML output from the LINQ is off, I'm not getting the email list:
<contacts>
<Data URL="site1" emails="System.String[] , " />
<Data URL="site2" emails="System.String[] , " />
</contacts>
How to get each of the i.Emails into their own xml nodes?