XmlDocument xmlDoc = new XmlDocument();
XmlNodeList nodes;
string xmlResp;
// convert string to stream
byte[] byteArray = Encoding.ASCII.GetBytes(xmlResp);
MemoryStream stream = new MemoryStream(byteArray);
xmlDoc = ConvertStreamToXMLDocument(stream);
nodes = xmlDoc.GetElementsByTagName("Items");
DataTable dt = Utility.ConvertXmlNodeListToDataTable(nodes);
public static DataTable ConvertXmlNodeListToDataTable(XmlNodeList xnl)
{
DataTable dt = new DataTable();
int TempColumn = 0;
foreach (XmlNode node in xnl.Item(0).ChildNodes)
{
TempColumn++;
DataColumn dc = new DataColumn(node.Name, System.Type.GetType("System.String"));
if (dt.Columns.Contains(node.Name))
{
dt.Columns.Add(dc.ColumnName = dc.ColumnName + TempColumn.ToString());
}
else
{
dt.Columns.Add(dc);
}
}
int ColumnsCount = dt.Columns.Count;
for (int i = 0; i < xnl.Count; i++)
{
DataRow dr = dt.NewRow();
for (int j = 0; j < ColumnsCount; j++)
{
//dr[j] = xnl.Item(i).ChildNodes[j].InnerText;
if (xnl.Item(i).ChildNodes[j] != null)
dr[j] = xnl.Item(i).ChildNodes[j].InnerText;
else
dr[j] = null;
}
dt.Rows.Add(dr);
}
return dt;
}