title: Problems reading an XML file and displaying value in textboxes
body: <p>I am trying to set up a settings area for my windows form where I will be able to save 4 sets of settings for my application. </p>
  
  <p>Writing to the XML file is not a problem as I can do that sucessfully without issue with my code so far.</p>
  
  <p>The problem comes with read the xml file. Essentially I would like when the user opens the settings form the values from the xml file are inserted to "specific" text boxes on the settings form.</p>
  
  <p>Is anyone able to tell me what I am doing wrong and if possible provide some sample code to help me get the reading part working?</p>
  
  <p>Code is below, i would like to add all id's (1 through 4) to be read in the settings box, just provided id1 for now until i can get the right code for the others.</p>
  
  <pre><code>Public Class SettingsFrm
  
  Private Sub SettingsFrm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      Dim rdxmlfile As String = "\\ServerA\ITDept\test\Settings.xml"
  
      'Create the xml xmlreader
      Dim XMLR As New Xml.XmlTextReader(rdxmlfile)
  
      'Read the id1 element
      XMLR.ReadStartElement("id1")
  
      'Read the value of the code1 element and display in the appropriate textbox
      XMLR.ReadStartElement("code1")
      XMLR.ReadString(CDtxtbx1.Text)
      XMLR.ReadEndElement()
  
      'Read the value of the docgroup1 element and display in the appropriate textbox
      XMLR.ReadStartElement("docgroup1")
      XMLR.ReadString(DGtxtbx1.Text)
      XMLR.ReadEndElement()
  
      'Read the value of the doctype1 element and display in the appropriate textbox
      XMLR.ReadStartElement("doctype1")
      XMLR.ReadString(DTtxtbx1.Text)
      XMLR.ReadEndElement()
  
      'Read the value of the docsubtype1 element and display in the appropriate textbox
      XMLR.ReadStartElement("docsubtype1")
      XMLR.ReadString(DSTtxtbx1.Text)
      XMLR.ReadEndElement()
  
      'close the id1 element
      XMLR.ReadEndElement()
  
      'close cml
      XMLR.Close()
  
  End Sub
  
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Dim svxmlfile As String = "\\ServerA\ITDept\test\Settings.xml"
  
      'Create the xml writer obeject
      Dim XMLW As New Xml.XmlTextWriter(svxmlfile, System.Text.Encoding.GetEncoding("UTF-8"))
  
      'xml format to be written as:
      '&lt;id1&gt;
      '   &lt;code1&gt; FTO &lt;/code1&gt;
      '   &lt;docgroup1&gt; Operations &lt;/docgroup1&gt;
      '   &lt;doctype1&gt; Funds Transfer &lt;/doctype1&gt;
      '   &lt;docsubtype1&gt; Out &lt;/docsubtype1&gt;
      '&lt;/id1&gt;
  
      XMLW.Formatting = Xml.Formatting.Indented
  
      'write id1
      XMLW.WriteStartElement("id1")
  
      ' &lt;code element&gt;
      XMLW.WriteStartElement("code1")
      XMLW.WriteValue(CDtxtbx1.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocGroup element&gt;
      XMLW.WriteStartElement("docgroup1")
      XMLW.WriteValue(DGtxtbx1.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocType element&gt;
      XMLW.WriteStartElement("doctype1")
      XMLW.WriteValue(DTtxtbx1.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocSubType element&gt;
      XMLW.WriteStartElement("docsubtype1")
      XMLW.WriteValue(DSTtxtbx1.Text)
      XMLW.WriteEndElement()
  
      'the end of id1
      XMLW.WriteEndElement()
  
      'write id2
      XMLW.WriteStartElement("id2")
  
      ' &lt;code element&gt;
      XMLW.WriteStartElement("code2")
      XMLW.WriteValue(CDtxtbx2.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocGroup element&gt;
      XMLW.WriteStartElement("docgroup2")
      XMLW.WriteValue(DGtxtbx2.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocType element&gt;
      XMLW.WriteStartElement("doctype2")
      XMLW.WriteValue(DTtxtbx2.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocSubType element&gt;
      XMLW.WriteStartElement("docsubtype2")
      XMLW.WriteValue(DSTtxtbx2.Text)
      XMLW.WriteEndElement()
  
      'the end of id2
      XMLW.WriteEndElement()
  
      'write id3
      XMLW.WriteStartElement("id3")
  
      ' &lt;code element&gt;
      XMLW.WriteStartElement("code3")
      XMLW.WriteValue(CDtxtbx3.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocGroup element&gt;
      XMLW.WriteStartElement("docgroup3")
      XMLW.WriteValue(DGtxtbx3.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocType element&gt;
      XMLW.WriteStartElement("doctype3")
      XMLW.WriteValue(DTtxtbx3.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocSubType element&gt;
      XMLW.WriteStartElement("docsubtype3")
      XMLW.WriteValue(DSTtxtbx3.Text)
      XMLW.WriteEndElement()
  
      'the end of id3
      XMLW.WriteEndElement()
  
      'write id4
      XMLW.WriteStartElement("id4")
  
      ' &lt;code element&gt;
      XMLW.WriteStartElement("code4")
      XMLW.WriteValue(CDtxtbx4.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocGroup element&gt;
      XMLW.WriteStartElement("docgroup4")
      XMLW.WriteValue(DGtxtbx4.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocType element&gt;
      XMLW.WriteStartElement("doctype4")
      XMLW.WriteValue(DTtxtbx4.Text)
      XMLW.WriteEndElement()
  
      ' &lt;DocSubType element&gt;
      XMLW.WriteStartElement("docsubtype4")
      XMLW.WriteValue(DSTtxtbx4.Text)
      XMLW.WriteEndElement()
  
      'the end of id4
      XMLW.WriteEndElement()
  
      'close the element
      XMLW.Close()
  
      MessageBox.Show("Settings Saved")
  End Sub
  
  End Class
  </code></pre>
  
  <p>I'm very new to VB.net and programming in general, so if there is an easier way to do what I am trying to do then I am all ears. I was first thinking of maybe using an INI file to store the settings of my settings form but after reading several forums I see that ini files are no longer used and is considered "dark ages".</p>
  
  <p>I am open to suggestions. My form looks like below:</p>
  
  <p><img src="https://i.stack.imgur.com/cZBpI.png" alt="settingsform"></p>
  
  <p>Any help or sample code would be most appreciated.</p>