Reputation: 5075
I am require to create xml file from array list in c#, which is working fine. what i need not to create node in xml for record whose value is coming # in record. so say example if # is this then don't create the node but if value from array list is coming string other than # then create node and store value in it.
many thanks
public void generateXMLFile(List<UWL> myList )
{
XDocument objXDoc = new XDocument(
new XElement("Institution",
new XElement("RECID", myList[0].recid),
new XElement("UKPRN", myList[0].UKPRN),
myList.Select(m => new XElement("Person",
new XElement("STAFFID", m.STAFFID),
new XElement("OWNSTAFFID", m.OWNSTAFFID),
new XElement("ACTCHQUAL", m.ABLWELSH)
)
)
)
);
objXDoc.Declaration = new XDeclaration("1.0", "utf-8", "true");
//
objXDoc.Save(@"C:\Test\generated.xml");
//Completed.......//
MessageBox.Show("Process Completed......");
}
Upvotes: 1
Views: 734
Reputation: 11955
Not sure what # represents, but say it is one of the values in the Person. In my example I picked STAFFID, but it could be any of the others or some other value in your UWL object you want to filter by:
Change your myList.Select
to:
myList
.Where(m => m != null)
.Where(m => m.STAFFID != value)
.Select(m => new XElement("Person",
new XElement("STAFFID", m.STAFFID),
new XElement("OWNSTAFFID", m.OWNSTAFFID),
new XElement("ACTCHQUAL", m.ABLWELSH)
)
)
Upvotes: 1