Hello

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.

Example:

<?xml version="1.0"?>

-<clients>


-<client id="1">

<name>Acrobedding (Cloud)</name>

<sender>cloud@acrobedding.com</sender>

<errorWords>failed|error</errorWords>

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

<link>e-mail adress</link>

<days>MA|DI|WO|DO|VR</days>

</client>

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
                    Console.WriteLine(">")
                Case XmlNodeType.Text 'Display the text in each element.
                    Console.WriteLine(reader.Value)
                Case XmlNodeType.EndElement 'Display end of element.
                    Console.Write("</" + reader.Name)
                    Console.WriteLine(">")
            End Select
        Loop
        Console.ReadLine()

    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.

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" ?>
<companies>
  <company>
    <name>ABC</name>
    <Address>india road</Address>
    <point></point>
  </company>
</companies>


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

        xdoc.Load("..\XMLFile1.xml")
        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.