- This topic explains about, how to add XML file data into DataGridView controls in C# programming.
- Tools needed: DataGridView1 (DataGridView1).
XML (Extensible Markup Language) – add XML data into DataGridView in C#
- Extensible Markup Language (XML) is a markup language created to structure, store, and transport data by defining a set of rules for encoding documents in a format that is both human-readable and machine-readable.
- The design goals of XML emphasize simplicity, generality, and usability over the Internet.
- XML is a textual data format with strong support via Unicode for the languages of the world.
- XML is developed by World Wide Web Consortium.
- Hundreds of XML-based languages have been developed, including RSS, Atom, SOAP, and XHTML.
XmlReader Class - add XML data into DataGridView in C#
- XMLReader Class represents a reader that provides fast, non-cached, forward-only access to XML data.
- Syntax for XmlReader Class
|
1 2 |
public abstract class XmlReader { } |
System.Data Namespace – add XML data into DataGridView in C#
- The System.Data namespace provides access to classes that represent the ADO.NET architecture. ADO.NET lets you build components that efficiently manage data from multiple data sources.
DataSet Class – add XML data into DataGridView in C#
- DataSet Class is used as in-memory of class.
- Syntax for DataSet Class
|
1 2 3 4 |
// Declaration [SerializableAttribute()] public class DataSet : MarshalByValueComponent, IListSource { } |
DataSet.ReadXml Method (XmlReader) – add XML data into DataGridView in C#
- Helps to read XML schema and data into the DataSet using the specified System.Xml.XmlReader.
- Syntax
|
1 2 3 |
// Declaration public XmlReadMode ReadXml(XmlReader reader) { } |
DataGridView.DataSource Property – Add XML data into DataGridView in C#
- It helps to assign the data source fully integrated into DataGridView with their columns and rows.
|
1 2 3 |
// Declaration public object DataSource { } |
Add XML data into DataGridView in C# – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { XmlReader xmlFile; xmlFile = XmlReader.Create("C:/Product.xml", new XmlReaderSettings()); DataSet ds = new DataSet(); ds.ReadXml(xmlFile); DataGridView1.DataSource = ds.Tables[0]; } } } |
| C# XML TOPICS |
| How to create XML file using C#? |
| How to read XML file using C#? |
| How to search XML file using C#? |
Add XML data into DataGridView in C#






