How to Open and read an XML file to Dataset
XML is a platform independent language, so the information formatted in XML can be use in any other platforms (Operating Systems) . The .Net technology is widely supported XML file format. The .Net Framework provides the Classes for read, write, and other operations in XML formatted files .
In the previous section we already saw how to read an XML file through Node navigation . Here we are going to read an XML file using a DataSet. Here Dataset is using an XmlReader for read the content of the file. Locate the XML file using XmlReader and pass the XmlReader as argument of Dataset.
Click here to download the input file product.xml : product.xml
Full Source C#
using System;
using System.Data;
using System.Windows.Forms;
using System.Xml;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
XmlReader xmlFile ;
xmlFile = XmlReader.Create("Product.xml", new XmlReaderSettings());
DataSet ds = new DataSet();
ds.ReadXml(xmlFile);
int i = 0;
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
MessageBox.Show(ds.Tables[0].Rows[i].ItemArray[2].ToString());
}
}
}
}
Related Topics
- How to XML in C#
- How to create an XML file in C#
- How to open and read XML file in C# , XmlReader , XmlTextReader , XmlDocument
- How to create XML file from Dataset
- How to create an XML file from SQL
- How to search in a XML file
- How to filter in a XML file
- How to insert data from XML to database
- How to create Excel file from XML
- How to create XML file from Excel
- How to XML to DataGridView
- How to create a TreeView from XML File
- How to create a Crystal Reports from XML File
- XML Serialization Tutorial
- XML Serialization
- XML DeSerialization