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 personsDataSource1 is my list):
XElement x1 =
new XElement("root",
new XElement("persons",
from p in personsDataSource1
select
new XElement("person",
new XAttribute("firstname", p.Firstname),
new XAttribute("Id", p.Age)
new XAttribute("deparementId", 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