COMO CARREGAR DADOS DO XML PARA VBNET

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Cria uma instância de um documento XML
        Dim oXML As New XmlDocument

        'Define o caminho do arquivo XML 
        Dim ArquivoXML As String = txtNomeArquivo.Text
        'carrega o arquivo XML
        oXML.Load(ArquivoXML)

        'Lê o filho de um Nó Pai específico 
        Dim nomeAluno As String = oXML.SelectSingleNode("Alunos").ChildNodes(0).InnerText
        Dim idadeAluno As String = oXML.SelectSingleNode("Alunos").ChildNodes(1).InnerText
        Dim emailAluno As String = oXML.SelectSingleNode("Alunos").ChildNodes(2).InnerText

        '*** Exibe Dados do aluno
        lstDados.Items.Add(nomeAluno)
        lstDados.Items.Add(idadeAluno)
        lstDados.Items.Add(emailAluno)

        'endereco do aluno
        For i = 0 To 4
            lstDados.Items.Add(oXML.SelectSingleNode("Alunos").ChildNodes(3).ChildNodes(i).InnerText)
        Next

    End Sub

3.78
9

                                     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Cria uma instância de um documento XML
        Dim oXML As New XmlDocument
        Dim oNoLista As XmlNodeList
        Dim oNo As XmlNode

        'Define o caminho do arquivo XML 
        Dim ArquivoXML As String = txtNomeArquivo.Text
        'carrega o arquivo XML
        oXML.Load(ArquivoXML)

        'Lê o filho de um Nó Pai específico 
        Dim nomeAluno As String = oXML.SelectSingleNode("Alunos").ChildNodes(0).InnerText
        Dim idadeAluno As String = oXML.SelectSingleNode("Alunos").ChildNodes(1).InnerText
        Dim emailAluno As String = oXML.SelectSingleNode("Alunos").ChildNodes(2).InnerText

        '*** Exibe Dados do aluno
        lstDados.Items.Add(nomeAluno)
        lstDados.Items.Add(idadeAluno)
        lstDados.Items.Add(emailAluno)

         ' Define o nó para nova leitura
        oNoLista = oXML.SelectNodes("/Alunos/Endereco")

        'percorre os nós filhos do Nó especificaod e obtem o atributo e os valores
        For Each oNo In oNoLista
            lstDados.Items.Add(oNo.Attributes.GetNamedItem("tipo").Value)
            lstDados.Items.Add(oNo.ChildNodes.Item(0).InnerText)
            lstDados.Items.Add(oNo.ChildNodes.Item(1).InnerText)
            lstDados.Items.Add(oNo.ChildNodes.Item(2).InnerText)
            lstDados.Items.Add(oNo.ChildNodes.Item(3).InnerText)
            lstDados.Items.Add(oNo.ChildNodes.Item(4).InnerText)
        Next

    End Sub

3.78 (9 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source