Read XML file as DataSet

As a novice in parsing XML files, I needed to save line graph data to an xml file and conducted some research. Based on an article I found, among all the techniques for reading an XML file, this one is the quickest.


As I am new to
parsing XML files
, I had to save line
graph data
as an XML file. To find the best way to read the XML file, I did some research. Based on an article I found,


is the quickest method out of all the options available. Considering the large amount of data, it is sensible to use


. This is how my graph documents are presented:


As there might be a considerable amount of points in these lines, obtaining the data using minimal resources and in a timely manner is crucial. If there exists a quicker method than


, kindly share it. Otherwise, can someone guide me on how to extract my graph data using an XML parser such as



Solution 1:

Utilizing a DataSet is an effortless task.

// Here your xml file
string xmlFile = "Data.xml";
DataSet dataSet = new DataSet();
dataSet.ReadXml(xmlFile, XmlReadMode.InferSchema);
// Then display informations to test
foreach (DataTable table in dataSet.Tables)
    for (int i = 0; i < table.Columns.Count; ++i)
        Console.Write("t" + table.Columns[i].ColumnName.Substring(0, Math.Min(6, table.Columns[i].ColumnName.Length)));
    foreach (var row in table.AsEnumerable())
        for (int i = 0; i < table.Columns.Count; ++i)
            Console.Write("t" + row[i]);

For faster results, consider using XmlReader to read one line at a time. However, note that it may be more challenging to create. You can view more information here:

Solution 2:

Another uncomplicated approach involves utilizing the built-in “ReadXml” method.

string filePath = "D:\Self Practice\Sol1\Sol1\Information.xml";
DataSet ds = new DataSet();

Please ensure that the XML file is in the format of
orderly manner


Frequently Asked Questions

Posted in Uncategorized