How to read an XML file in VB.NET using ADO.NET - Dataset

XML, an acronym for eXtensible Markup Language, is an exemplary platform-agnostic dialect, showcasing its ability to transcend the boundaries of any specific operating system or platform. The ingenious nature of XML enables information to be carefully organized and formatted in a manner that seamlessly harmonizes with diverse operating systems, thereby guaranteeing unrivaled versatility and cross-compatibility.

Of major significance is the immense popularity and extensive adoption of XML within the areas of .Net technology, as it enjoys widespread support as the favored file format. The ingenious integration of XML within the .Net Framework further amplifies its significance, facilitating a robust repertoire of classes that empower developers with the ability to effortlessly perform a myriad of operations on XML-formatted files. This comprehensive suite of capabilities encompasses the ability to effectively read, write, manipulate, and perform an assortment of other intricate operations with utmost precision and finesse.

Read an XML file using ADO.NET

In the preceding section, we have already familiarized ourselves with the process of read an XML file through Node navigation. In this section, we will investigate into an alternative method of reading an XML file by employing a DataSet. The Dataset, in this context, utilizes an XmlReader to carefully extract the contents of the aforementioned file.

To initiate the procedure, the first step entails locating the XML file utilizing the capabilities offered by the XmlReader. Once the file has been successfully identified, we proceed to pass the XmlReader as an argument to the Dataset, thereby facilitating the seamless extraction and processing of the XML data within the confines of the DataSet.

Click here to download the input file product.xml

Full Source VB.NET
Imports System.Xml Imports System.Data Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim xmlFile As XmlReader xmlFile = XmlReader.Create("Product.xml", New XmlReaderSettings()) Dim ds As New DataSet ds.ReadXml(xmlFile) Dim i As Integer For i = 0 To ds.Tables(0).Rows.Count - 1 MsgBox(ds.Tables(0).Rows(i).Item(1)) Next End Sub End Class

Through the amalgamation of XML and the .Net Framework, developers are presented with an all-encompassing toolset that empowers them to utilize the full potential of XML's innate flexibility and portability. This synergy between the two entities endows developers with unparalleled possibilities, granting them the freedom to effortlessly exchange, manipulate, and interpret information across an extensive array of operating systems and platforms, all while upholding the integrity and structure of the underlying XML data.


We have explored an alternative technique for reading an XML file using a Dataset in this section. By using the capabilities of the XmlReader, we are able to locate and seamlessly extract the XML content. Integrating the XmlReader with the Dataset equips us with a powerful toolset for efficiently working with XML files, empowering us to unlock their full potential for data analysis and manipulation.