I have an assignment where I have a XML file with data and I need to able to read it inside something like a listbox where I'm able to select the name of a company and all the other data related to that company name is shown.


<?xml version="1.0"?>


-<client id="1">

<name>Acrobedding (Cloud)</name>



<falseWords>Warnings: []|Errors: []|Failed to process path:|FilesWithError: 0|VerboseErrors:</falseWords>

<link>e-mail adress</link>



So for example I have to able to select Acrobedding from a list and all the other data shows in a label or textbox (Sender, Errorwords, ...)

I have been able to read all the data in VB in a cmd but it's nothing like the end result it should be.

Here's what I have:

Imports System.Xml

Module Module1

    Sub Main()
        Dim reader As XmlTextReader = New XmlTextReader("input.xml")

        Do While (reader.Read())
            Select Case reader.NodeType
                Case XmlNodeType.Element 'Display beginning of element.
                    Console.Write("<" + reader.Name)
                    If reader.HasAttributes Then 'If attributes exist
                        While reader.MoveToNextAttribute()
                            'Display attribute name and value.
                            Console.Write(" {0}='{1}'", reader.Name, reader.Value)
                        End While
                    End If
                Case XmlNodeType.Text 'Display the text in each element.
                Case XmlNodeType.EndElement 'Display end of element.
                    Console.Write("</" + reader.Name)
            End Select

    End Sub

If anyone knows a solution for my problem it would be much appreciated and if you need to know more then feel free to ask as I will check this post frequently while I search for more solutions.

3 Years
Discussion Span
Last Post by asarchit65

try some thing like this.

1) collect all company names from xmlfile and load in to combobox or some control
2) load company details in listview based on seletion.

<?xml version="1.0" encoding="utf-8" ?>
    <Address>india road</Address>

  Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Dim xlist = (From xlit In xdoc.SelectNodes("companies/company") Select DirectCast(xlit, XmlNode).SelectSingleNode("name").InnerText).ToList()
        ComboBox1.DataSource = xlist
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click

        Dim CompanyDetails = (From xlit In xdoc.SelectNodes("companies/company") Where DirectCast(xlit, XmlNode).SelectSingleNode("name").InnerText.Equals(ComboBox1.SelectedValue) Select xlit).FirstOrDefault()

        ListView1.Items.Add(DirectCast(CompanyDetails, XmlNode).SelectSingleNode("name").InnerText)
        ListView1.Items(0).SubItems.Add(DirectCast(CompanyDetails, XmlNode).SelectSingleNode("Address").InnerText)

    End Sub
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.