title: Parsing a XML File and Replacing Chosen Node With Values From Text File
body: <p>I wrote a C# Winforms program to take a XML file and load values from a text file into each occurrence of that field which the user specifies on the UI. For whatever reason, the program inserts a carriage return on any nodes which don't contain a value. For example, it will do that to <code>&lt;example&gt;&lt;/example&gt;</code> whereas it will not misbehave on something like <code>&lt;country&gt;USA&lt;/country&gt;</code></p>
  
  <p>What is causing it to do this and how can I prevent it? Here is the code from the part which handles this functionality.</p>
  
  <pre><code>XmlDocument LoadXmlDoc = new XmlDocument();
  StreamReader sr = File.OpenText(DataLoadTxtBx.Text);
  string InputFromTxtFile;
  LoadXmlDoc.Load(XmlPath.Text);
  
  XmlNodeList NodeToCreateOrReplace = LoadXmlDoc.GetElementsByTagName(XmlTagNameTxtBx.Text);
  
  foreach (XmlNode SelectedNode in NodeToCreateOrReplace)
  {
      if ((InputFromTxtFile = sr.ReadLine()) != null)
      {
          SelectedNode.InnerText = InputFromTxtFile;
      }
  }
  sr.Close();
  LoadXmlDoc.Save(XmlPath.Text);
  </code></pre>