How to XML to DataGridView

XML, being a platform-independent language, offers the significant advantage of facilitating the interchangeability of information formatted within XML files across diverse platforms. The .NET technology ecosystem widely embraces and supports XML as a standard file format, recognizing its universal compatibility and wide adoption. The comprehensive support provided by the .NET technology ensures seamless integration and utilization of XML files within various applications and systems, enabling efficient data interchange and fostering interoperability across platforms.

XML to DataGridView

The following C# source code demonstrates how to load data from an XML file into a DataGridView. In this example, a Dataset is utilized, employing an XmlReader to read the content of the XML file, specifically the "Product.XML" file. The XmlReader is utilized to locate the XML file and is passed as an argument to the Dataset. Once the Dataset retrieves the data, it is set as the DataSource for the DataGridView, effectively populating the DataGridView with the XML file's content. This process enables the seamless display and visualization of XML data within the DataGridView, offering a user-friendly and interactive interface for data presentation and manipulation.

Full Source C#
using System; using System.Data; using System.Windows.Forms; using System.Xml; using System.Data; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { XmlReader xmlFile ; xmlFile = XmlReader.Create("Product.xml", new XmlReaderSettings()); DataSet ds = new DataSet(); ds.ReadXml(xmlFile); dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ex) { MessageBox.Show (ex.ToString()); } } } }

Click here to download the input file product.xml