Hi All
I am trying to get vb.net to select a single node by id. I then want get all of the childnodes within the id and place them in to textboxes. Please see code below:

Xml doc

    <Item id="1">
    <Item id="2">

Vb code

Dim doc As New XmlDocument()

 Dim n As XmlNode = doc.SelectSingleNode("/Subject/Items/Item[@ID='1']")
 TextBox1.Text = n("CustName").InnerText

Have scoured google and Daniweb forums but cannot find the answer im looking for.

Thanks for your help in advance


See if this helps.
1 Button

Imports System.Xml
Public Class Form1
    Private myXML_FileLocation As String = "C:\test.xml" '// .xml file and location.
    Private xmlDoc As New XmlDocument, xmlSelectedNode As XmlNode

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        xmlDoc.Load(myXML_FileLocation) 'Load the Xml file once if constantly in use.
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    End Sub
    Private Sub getXMLnodeByID(ByVal IDToUse As String)
        xmlSelectedNode = xmlDoc.SelectSingleNode("Subject/Items/Item[@id='" & IDToUse & "']")
        With xmlSelectedNode
            '// etc...
        End With
    End Sub
End Class

I noticed that your .xml file has <Item id="1"> which is all LowerCase and you were using ("/Subject/Items/Item[@ID='1']") .ToUpper, which will result in errors. At least it did on my part.

Thanks codeorder

Just found another way about 2 hours ago that works well. I have posted it below for anyone elses reference

Dim doc As New XmlDocument()
        Dim nodes As XmlNodeList

        nodes = doc.SelectNodes("/Subject/Items/Item[@id=" & Module1.Client_id & "]")

        Dim node As XmlNode
        For Each node In nodes
            TextBox1.Text = node.SelectSingleNode("CustName").InnerText
            TextBox4.Text = node.SelectSingleNode("PayFrequency").InnerText
            TextBox5.Text = node.SelectSingleNode("Cost").InnerText

Much appreciated for your time and effort