Read xml in VB.net

Asked

Viewed 398 times

0

I’d like to read the line tag version="1.0.1.0" and store in a variable in Vb.Net?

<?xml version="1.0" encoding="utf-8"?>
<Feed>
  <Tasks>
    <FileUpdateTask hotswap="false" updateTo="file://d:\tmp\update\AtualizadorAplicacao.exe" localPath="AtualizadorAplicacao.exe">
      <Description>Descricao da nova versao.</Description>
      <Conditions>
        <FileVersionCondition what="below" version="1.0.1.0" />
      </Conditions>
    </FileUpdateTask>
  </Tasks>
</Feed>
  • http://www.macoratti.net/10/08/vbn_xml1.htm

1 answer

0

Assuming your XML is in the file C: temp Vbwpfapp1 Myfile.xml;
With this code you will be able to read the value of attribute version:

Dim oXML As New XmlDocument

Dim ArquivoXML As String = "C:\temp\VBWpfApp1\MeuArquivo.xml"

oXML.Load(ArquivoXML)        ' Carrega o arquivo XML

Dim oNo = oXML.SelectSingleNode("/Feed/Tasks/FileUpdateTask/Conditions/FileVersionCondition")
Dim versao = oNo.Attributes.GetNamedItem("version").Value
  • Greetings. @Tony In the second line of code you created a variable (Arquivoxml) to play the xml file through your path. You could not put the path between load? parentheses in c# works. ex: [oXML.Load("C: Vbwpfapp1 temp Myfile.xml")]

  • Might as well, it would work too.

  • If it worked, please +1 and mark as Reply. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.