unathi guma

unathi guma

  • NA
  • 40
  • 9.8k

Generating the DataTable from the XML file

Feb 26 2019 7:31 AM
I got this code here and it's giving me errors.
public DataTable CreateDataTableXML(string XmlFile)
{
XmlDocument doc = new XmlDocument();
doc.Load(XmlFile);
try
{
Dt.TableName = GetTableName(XmlFile);
XmlNode NodoEstructura = doc.DocumentElement.ChildNodes.Cast.ToList()[0];
progressBar1.Maximum = NodoEstructura.ChildNodes.Count;
progressBar1.Value = 0;
foreach (XmlNode columna in NodoEstructura.ChildNodes)
{
Dt.Columns.Add(columna.Name, typeof(String));
Progress();
}
XmlNode Filas = doc.DocumentElement;
progressBar1.Maximum = Filas.ChildNodes.Count;
progressBar1.Value = 0;
foreach (XmlNode Fila in Filas.ChildNodes)
{
List<string> Valores = Fila.ChildNodes.Cast().ToList().Select(x => x.InnerText).ToList();
Dt.Rows.Add(Valores.ToArray());
Progress();
}
}
catch (Exception ex)
{
}
return Dt;
}

Answers (9)