Convert XML file to Dataset
We can convert XML file to Dataset using below steps.
Steps:
1. XML file path declaration.
2. Dataset object declaration.
3. Loading xml file to dataset using ReadXml method.
Input xml file contains:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Customer_Details>
<Customer>
<CustomerId>1111</CustomerId>
<CustomerName>Ranga Rajesh</CustomerName>
</Customer>
<Customer>
<CustomerId>1112</CustomerId>
<CustomerName>Anil Kumar</CustomerName>
</Customer>
<Customer>
<CustomerId>1113</CustomerId>
<CustomerName>Murthy</CustomerName>
</Customer>
<Customer>
<CustomerId>1114</CustomerId>
<CustomerName>Sanjeev</CustomerName>
</Customer>
</Customer_Details>
Output : Loaded XML file into dataset
Convert XML file to Dataset |
Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace xmltodataset
{
class Program
{
static void Main(string[] args)
{
try
{
string strFileName = @"c://customer.xml";
DataSet objDataSet = new DataSet();
objDataSet.ReadXml(strFileName);
Console.WriteLine(objDataSet.Tables[0].Rows[0].ItemArray[1].ToString());
Console.Read();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
Previous Home Next
Post a Comment
Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.