title: XmlDocument combining nodes into the same line
body: <p>I have an application that edits an XML file.</p>
  
  <p>The problem is, that after I save my file, some nodes get combined onto one line.</p>
  
  <p><strong>Example:</strong>
  I want to edit child-node B  </p>
  
  <pre><code>&lt;root&gt;
      &lt;A&gt;
        &lt;B&gt;
          &lt;C&gt;somedata&lt;/C&gt;
          ...
        &lt;/B&gt;
      &lt;/A&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>After edit I get:</p>
  
  <pre><code>&lt;root&gt;
      &lt;A&gt;
       &lt;B&gt;&lt;C&gt;EditedData&lt;/C&gt;&lt;/B&gt;
      &lt;/A&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>My code Is</p>
  
  <pre><code>public static bool WriteNodeInnerText(List&lt;string&gt; NodesHirarchi, string InnerText, string PathToXml)
  {
      if (NodesHirarchi.Count == 0) return false;
  
      XmlDocument doc = new XmlDocument();
      doc.Load(PathToXml);
  
      doc.PreserveWhitespace = true;
  
      XmlNode xmlNode;
      StringBuilder nodesPath = new StringBuilder();
      NodesHirarchi.ForEach(x =&gt; nodesPath.Append(string.Format("//{0}", x)));
      try
      {
          xmlNode = doc.SelectSingleNode(nodesPath.ToString());
      }
      catch (System.Xml.XPath.XPathException ex)
      {
          Console.WriteLine(ex.Data);
          return false;
      }
  
      XmlWriterSettings settings = new XmlWriterSettings
      {
          Indent = true,
          IndentChars = "  ",
          NewLineChars = "\r\n",
          NewLineHandling = NewLineHandling.Replace,
      };
  
      using (XmlWriter writer = XmlWriter.Create(PathToXml,settings))
      {
          xmlNode.InnerText = InnerText;
          doc.Save(writer);
      }
      return true;
  }
  </code></pre>
  
  <p>please Help me solve it + any comment about the code will be appreciated </p>