How to Import XLM Into Visual Basic

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Import XLM Into Visual Basic
Read XML files in VB. (Jupiterimages/ Images)

XML files are widely used and it can be handy to know how to import XML data into your Visual Basic application. To accomplish this task you need to use the "System.Xml" assembly. This assembly contains the "XmlTextReader" class, which you can use to read Externsible Markup Language (XML) from a file. The reader provides direct parsing and tokenizing of XML. The data read is stored in memory that you can access and use in your VB program.

Skill level:


  1. 1

    Launch Microsoft Visual Basic Express, click "New Project" from the left pane of your computer screen and click "Console Application." Click "OK" to create a new console project.

  2. 2

    Add the following line of code as the first line of your code module:

    Imports System.Xml

  3. 3

    Type the following code to define the XML reader and the XML file to read:

    Dim reader As XmlTextReader = New XmlTextReader("C:\xmlFile.xml")

  4. 4

    Copy and paste the following code to read the XML file and display its contents through the Console window:

    Do While (reader.Read())

            Select Case reader.NodeType
                Case XmlNodeType.Element
                    Console.Write("<" + reader.Name)
                    If reader.HasAttributes Then
                        While reader.MoveToNextAttribute()
                            Console.Write(" {0}='{1}'", reader.Name, reader.Value)
                        End While
                    End If
                Case XmlNodeType.Text
                Case XmlNodeType.EndElement
                    Console.Write("</" + reader.Name)
            End Select
  5. 5

    Press "F5" to run the project and display the XML file contents.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.