---
title: "How i can read xml into DataTable type object?"  
description: "How i can read xml into DataTable type object?"  
author: "Jayden Bell"  
published: 2014-01-30  
updated: 2014-01-30  
canonical: https://www.mindstick.com/forum/1921/how-i-can-read-xml-into-datatable-type-object  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How i can read xml into DataTable type object?

I don't have [problem if](https://answers.mindstick.com/qa/50244/how-can-you-fix-the-problem-if-there-is-a-message-saying-the-windows-logon-ui-encountered-a-problem-and-needed-to-close-and-if-the-system-restoring-won-t-work) i read [xml](https://www.mindstick.com/blog/203/working-with-xml-data-in-sql-server) to [DataSet](https://www.mindstick.com/articles/19/dataset):

```
DataSet temp = new DataSet();temp.ReadXml(UncompressedStream,
System.Data.XmlReadMode.Auto);
```

But if i use [DataTable](https://www.mindstick.com/blog/195/datatable-in-ado-dot-net):

```
DataTable temp = new DataTable();temp.ReadXml(UncompressedStream);then datatable not load data (count of columns and rows
equal 0 )
```

## How i can read xml to DataTable

**My [temporary](https://www.mindstick.com/forum/2292/how-to-set-temporary-path-of-jdk-in-windows) solution:**

```
DataSet temp = new DataSet();DataTable structure = new DataTable();temp.ReadXml(UncompressedStream,
System.Data.XmlReadMode.Auto);structure = temp.Tables[0];
```

## Replies

### Reply by Pravesh Singh

Hi Jayden,\
Try this:\

```
private static void DemonstrateReadWriteXMLDocumentWithString(){    DataTable table = CreateTestTable("XmlDemo");    PrintValues(table,"Original table");    string fileName ="C:\\TestData.xml";   
table.WriteXml(fileName, XmlWriteMode.WriteSchema);    DataTable newTable= new DataTable();   
newTable.ReadXml(fileName);    // Print out values in the table.    PrintValues(newTable, "New table");}private static DataTable CreateTestTable(string tableName){    // Create a test DataTable with two columns and a few rows.    DataTable table = new DataTable(tableName);    DataColumn column = new DataColumn("id", typeof(System.Int32));   
column.AutoIncrement = true;   
table.Columns.Add(column);    column = new DataColumn("item", typeof(System.String));   
table.Columns.Add(column);    // Add ten rows.    DataRow row;    for (int i = 0; i<= 9; i++)    {        row = table.NewRow();       
row["item"] = "item " + i;       
table.Rows.Add(row);    }   
table.AcceptChanges();    return table;}
```


---

Original Source: https://www.mindstick.com/forum/1921/how-i-can-read-xml-into-datatable-type-object

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
