Results 1 to 2 of 2

Thread: XML and Listbox question

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    43

    XML and Listbox question

    Hi again gurus , I am currently working on a form which contains a listbox and a few text fields. I am using an xml file that looks like this:

    <?xml version="1.0"?>
    <Sessionlist>
    <session name="rx30">
    <sessionname>rx30</sessionname>
    <sessionhost>192.168.0.254</sessionhost>
    <sessionuser>user</sessionuser>
    <sessionpass>pass</sessionpass>
    </session>
    <session name="rx30extra">
    <sessionname>rx30extra</sessionname>
    <sessionhost>192.168.0.254</sessionhost>
    <sessionuser>user</sessionuser>
    <sessionpass>pass</sessionpass>


    </session>
    </Sessionlist>

    I am able to populate the listbox with the sessionname node by using xmltextreader by doing the following:

    Code:
    Dim xmlfile As String = "c:\sessionlist.xml"
        Dim xmldoc As New XmlDocument
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim openfile As New XmlTextReader(xmlfile)
    
            While openfile.Read
                If openfile.Name = "sessionname" AndAlso openfile.NodeType = XmlNodeType.Element Then
                    ListBox1.Items.Add(openfile.ReadString)
                End If
            End While
            openfile.Close()
    
           
        End Sub
    What I want to be able to do is click an item and have the text fields populate with specific node information. I have read numerous tutorials, and read some info on this - but i cant get it to work and am getting fustrated. I have tried the following with no success:

    Code:
    Dim node As XmlNode = xmldoc.SelectSingleNode( _
                "session/Sessionlist/session[" & position & "]")
            sessionname.Text = node.SelectSingleNode("@name").InnerText
            hostname.Text = node.SelectSingleNode("sessionhost").InnerText
            userbox.Text = node.SelectSingleNode("sessionuser").InnerText
    Please help if you can - i know this may be a newbie question, but I am just that.. a newbie! Thanks in advance.

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    43

    Re: XML and Listbox question

    This is resolved.. I managed to figure it out.. I didnt load the darn document a second time in the form1_load sub.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width