Skip the ReadXml method and add the columns and rows to the DataTable yourself then. Something like this:
string strXML = "<root><trlFlags><trlFstmp /></trlFlags><trlFlags><trlPLU /></trlFlags></root>";
//check if the xml is properly parsed
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strXML);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds.Tables.Add(dt);
XmlNodeList trlFlags = xmlDoc.SelectNodes("//trlFlags");
foreach (XmlNode node in trlFlags)
{
DataRow dr = dt.NewRow();
foreach (XmlNode childNode in node)
{
var existingColumn = dt.Columns.Cast<DataColumn>().FirstOrDefault(c => c.ColumnName.Equals(childNode.Name));
if (existingColumn == null)
{
dt.Columns.Add(new DataColumn(childNode.Name));
}
dr[childNode.Name] = "1";
}
dt.Rows.Add(dr);
}
Hope that helps.
Please remember to mark all helpful posts as answer to close your threads and please start a new thread if you have a new question.
No comments:
Post a Comment