title: Read then write html to xml file using linq xml and xml writer
body: <p>I am reading the <code>Value</code> of a element <code>&lt;content&gt;Text with &lt;br /&gt; break&lt;/content&gt;</code> into a string and showing that string in a <code>TextBox</code>. Afterwards the user can modify it possibly with additional HTML tags. Upon using linq to query the exact node to insert the user-input all spiky bracket &lt;> from html tags are normalized into <code>&amp;lt;br /&amp;gt;</code>. So how do I preseve my html tags?</p>
  
  <p>I already read and tried the solutions from these questions but I failed to apply it to my use case:
  <a href="https://stackoverflow.com/questions/19271080/c-sharp-xml-avoid-html-encode-using-xdocument">c# XML avoid html encode using XDocument</a></p>
  
  <p><a href="https://stackoverflow.com/questions/1243868/get-html-tags-embedded-in-xml-using-linq">Get html tags embedded in xml using linq</a></p>
  
  <p><a href="https://stackoverflow.com/questions/457970/keep-html-tags-in-xml-using-linq-to-xml">Keep HTML tags in XML using LINQ to XML</a></p>
  
  <p><a href="http://blogs.msdn.com/b/charlie/archive/2008/09/29/linq-farm-preserving-formats-with-linq-to-xml.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/b/charlie/archive/2008/09/29/linq-farm-preserving-formats-with-linq-to-xml.aspx</a></p>
  
  <p>This is an example of my xml file:</p>
  
  <pre><code>&lt;events&gt;
      &lt;event id="0"&gt;
          &lt;content&gt;&lt;br/&gt;&lt;/content&gt;
      &lt;/event&gt;
  &lt;/events&gt;
  </code></pre>
  
  <p>How I load and query:</p>
  
  <pre><code>XDocument xml;
  XmlTextReader xtr = new XmlTextReader(this.pathXML);
  
  xtr.Normalization = false;
  xml = XDocument.Load(xtr, LoadOptions.PreserveWhitespace);
  xtr.Close();
  
  var nodeToEdit = xml.Descendants("event").Where(x =&gt; (string)x.Attribute("id") == "0");
  </code></pre>
  
  <p>How I manipulate my xml file with user input:</p>
  
  <pre><code>string userinput = "Text with &lt;br /&gt; break"; // This is read from TextBox control inside Form
  foreach (var item in nodeToEdit.Elements())
  {
      if(item.Name == "content")
      {
          item.Value = userinput;
      }
  }
  </code></pre>
  
  <p>How I save:</p>
  
  <pre><code>changeSaveIndent(xml, this.pathXML);
  public static void changeSaveIndent(XDocument x, string path)
  {
      XmlWriterSettings settings = new XmlWriterSettings();
      settings.Indent = true;
      // Indent by tab. Can be changed to "    " or similar
      settings.IndentChars = "\t";
  
      using (XmlWriter writer = XmlTextWriter.Create(path, settings))
      {
          x.Save(writer);
      }
  }
  </code></pre>
  
  <p>My expected xml output file should look like this:</p>
  
  <pre><code>&lt;events&gt;
      &lt;event id="0"&gt;
          &lt;content&gt;Text with &lt;br /&gt; break&lt;/content&gt;
      &lt;/event&gt;
  &lt;/events&gt;
  </code></pre>
  
  <p>sorry for the long post..</p>