• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Read XML File using vb.net

I needed to read the contents of a XML file.  Below is a the contents of the file:

<?xml version="1.0"?>
<!--Test file for database settings-->
<Settings>
  <DB_Type>SQL</DB_Type>
  <DB_Security>Standard</DB_Security>
  <DB_Name />
  <DB_Login />
  <DB_Password />
  <DB_Table />
  <DB_Connection_TO>30</DB_Connection_TO>
</Settings>

What would be a quick way to read each of the values in this file?  I am using vb.net
0
Mike_Stevens
Asked:
Mike_Stevens
  • 2
  • 2
1 Solution
 
Wayne Taylor (webtubbs)Commented:
Hello Mike_Stevens,

Try this....

        Dim xmlDoc As New Xml.XmlDocument
        xmlDoc.Load("C:\YourFile.xml")
        For Each nd As Xml.XmlNode In xmlDoc.DocumentElement
            MsgBox(nd.Name & " = " & nd.InnerText)
        Next

Regards,

Wayne
0
 
Mike_StevensAuthor Commented:
I need to be able to read each node and then assign the value to a textbox...

ex...

Me.textbox1.text = "the value of DB_Type node"
Me.textbox1.text = "the value of DB_Security node"
0
 
Wayne Taylor (webtubbs)Commented:
       Dim xmlDoc As New Xml.XmlDocument
        xmlDoc.Load("C:\YourFile.xml")
        TextBox1.Text = xmlDoc.DocumentElement.SelectSingleNode("DB_Type").InnerText
        TextBox2.Text = xmlDoc.DocumentElement.SelectSingleNode("DB_Security").InnerText
        TextBox3.Text = xmlDoc.DocumentElement.SelectSingleNode("DB_Name").InnerText
        TextBox4.Text = xmlDoc.DocumentElement.SelectSingleNode("DB_Login").InnerText
        TextBox5.Text = xmlDoc.DocumentElement.SelectSingleNode("DB_Password").InnerText
        TextBox6.Text = xmlDoc.DocumentElement.SelectSingleNode("DB_Table").InnerText
        TextBox7.Text = xmlDoc.DocumentElement.SelectSingleNode("DB_Connection_TO").InnerText

0
 
Mike_StevensAuthor Commented:
Thanks...you are the best!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now