User-543160537 posted
Hi,
I am trying to generate XML from excel data, but in one of the element if there is no data i have to skip the starting and ending element but it is showing up elements if there is no data.
var UniCptyEmployees = (from DataRow dr in EventDetails.Rows select dr["FirstName"]).Distinct();
writer.WriteStartElement("CounterPartyEmployees");
foreach (var itememp in UniCptyEmployees)
{
if (uniquecpemployees.Rows.Count > 0)
{
bool flag = false;
//Check whether the title columns contains values
for (int j = 0; j < uniquecpemployees.Rows.Count; j++)
{
if (!string.IsNullOrEmpty(uniquecpemployees.Rows[j]["CS FirstName"].ToString()))
{
flag = true;
break;
}
}
if (!string.IsNullOrEmpty(uniquecpemployees.Rows[0]["CS FirstName"].ToString()))
{
if (flag)
{
for (int k = 0; k < uniquecpemployees.Rows.Count; k++)
{
writer.WriteStartElement("CounterPartyEmployee");
writer.WriteAttributeString("FirstName", null, uniquecpemployees.Rows[k]["CS FirstName"].ToString());
writer.WriteFullEndElement();
}
}
}
}
}
writer.WriteFullEndElement();// end Attendences
If the row is empty it is adding <CounterPartyEmployees></CounterPartyEmployees> which i need to skip.
Can someone please help..
Thanks