How to open and read XML file in VB.NET

XML is a self describing language and it gives the data as well as the rules to extract what the data it contains. Reading an XML file means that we are reading the information embedded in XML tags in an XML file.

VB.Net XML Parser

how to load xml in VB.Net

In the previous program we create an XML file and named it as products.xml. The following program read that file and extract the contents inside the XML tag. We can read an XML file in several ways depends on our requirement. This program read the content in Node wise . Here we are using XmlDataDocument class to read the XML file . In this program it search the Node < Product > and its child Nodes and extract the data in child nodes.

Click here to download the input file : product.xml

How to read XML from a file in VB.Net

Reading Xml with XmlReader in VB.Net

VB.Net XML Handling

XmlReader is a faster and less memory consuming alternative. It provides a lower-level abstraction over the XML file structure. The XmlReader class allows you run through the XML string one element at a time, while allowing you to look at the value, and then moves on to the next XML element.

VB.Net XML Handling

Full Source : Reading Xml with XmlReader

Reading XML with XmlTextReader in VB.Net

XmlTextReader Class provides forward-only, read-only access to a stream of XML data.

Full Source : Reading Xml with XmlReader

Reading XML with XmlDocument in VB.Net

Introduction to XML with

XmlDocument reads the entire XML content into memory and then allow you to navigate back and forward in it or even query the XML document using the XPath technology.

Click here to download the input file : product.xml

Imports System.Xml
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim xmlDoc As New XmlDocument()
        Dim nodes As XmlNodeList = xmlDoc.DocumentElement.SelectNodes("/Table/Product")
        Dim pID As String = "", pName As String = "", pPrice As String = ""
        For Each node As XmlNode In nodes
            pID = node.SelectSingleNode("Product_id").InnerText
            pName = node.SelectSingleNode("Product_name").InnerText
            pPrice = node.SelectSingleNode("Product_price").InnerText
            MessageBox.Show(pID & " " & pName & " " & pPrice)
    End Sub
End Class (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About