How to read data from an aquiver.xml and display in a textbox

3

I have an application that generates an XML file, but I am not able to read the XML file and insert it into the TextBox.

 <?xml version="1.0"?>
 <parametros>
  <banco>rango</banco>
  <caminho>C:\</caminho>
 </parametros>

I need the application to read this xml and "import" the information into a textbox.

    
asked by anonymous 10.10.2014 / 19:37

2 answers

3

The answer is this: '

 XmlTextReader x = new XmlTextReader(@".\SS-BACKUP.xml");

            while (x.Read())
            {
                if (x.NodeType == XmlNodeType.Element && x.Name == "banco")
                    cb_Banco.Text = (x.ReadString());
                if (x.NodeType == XmlNodeType.Element && x.Name == "caminho")
                    tb_Caminho.Text = (x.ReadString());
                if (x.NodeType == XmlNodeType.Element && x.Name == "servidor")
                    tb_Servidor.Text = (x.ReadString());
                if (x.NodeType == XmlNodeType.Element && x.Name == "usuario")
                    tb_Usuario.Text = (x.ReadString());
                if (x.NodeType == XmlNodeType.Element && x.Name == "senha")
                    tb_Senha.Text = (x.ReadString());
            }

            x.Close();
            return;
    
14.10.2014 / 14:50
1

Based on what you had, added assigns a + textBox that will work as an append.

XmlTextReader reader = new XmlTextReader("C:\Users\diego-santos\Desktop\teste.xml");

while (reader.Read())
{
  if (reader.NodeType == XmlNodeType.Text)
  {
      tb_Caminho.Text += reader.Value;
  }
}

or result = rangeC: \

    
10.10.2014 / 23:21