Hi all
I have a List of person objects using Generics. Each person will have
an Id, firstname and may have a DepartmentId
I am trying to convert this list to xml. However if the person doesnt
have a departmentId, I dont want to write out a departmentId
attribute. However I dont know how I can achieve this... I have tried
(assuming personsDataSour ce1 is my list):
XElement x1 =
new XElement("root" ,
new XElement("perso ns",
from p in personsDataSour ce1
select
new XElement("perso n",
new XAttribute("fir stname", p.Firstname),
new XAttribute("Id" , p.Age)
new XAttribute("dep arementId", p.DepartmentId)
)));
I need some conditional check againt the deparementId attribute, and
only write it if that conditon is true - How can I do this using Linq
to XML?
Many thanks