Thursday, 17 March 2016

C# code to convert xml into Dataset

How to convert xml file into dataset in C# programming.
In this blog i will show you how we can get xml data into a dataset.



Below is the xml file structure which tells about product category and item details.

<?xml version="1.0" encoding="utf-8" ?>
<root>
  <product category="electronics">
    <item name="tv" price="12000"></item>
    <item name="mobile" price="7000"></item>
    <item name="ac" price="25000"></item>
    <item name="laptop" price="22000"></item>
  </product>
  <product category="furniture">
    <item name="chair" price="1200"></item>
    <item name="table" price="2000"></item>
    <item name="computer table" price="2500"></item>   
  </product>
</root>


C# code:

DataSet ds = new DataSet();

ds.ReadXml(Server.MapPath("~/File1.xml"));

In Data Visualizer we may found 2 tables i.e. product and item. Refer below screen shot.



No comments:

Post a Comment