title: Remove self-closing tags (e.g. />) in an XmlDocument
body: <p>In an XmlDocument, either when writing and modify later, is it possible to remove the self-closing tags (i.e.  <code>/&gt;</code>) for a certain element. </p>
  
  <p>For example: change   </p>
  
  <ul>
  <li><code>&lt;img /&gt;</code> or <code>&lt;img&gt;&lt;/img&gt;</code> to <code>&lt;img&gt;</code>.</li>
  <li><code>&lt;br /&gt;</code> to <code>&lt;br&gt;</code>.  </li>
  </ul>
  
  <p>Why you ask? I'm trying to conform to the <em>HTML for Word 2007</em> schema; the resulting HTML will be displayed in <em>Microsoft Outlook 2007</em> or later. </p>
  
  <p>After reading another <a href="https://stackoverflow.com/questions/2107909/how-to-remove-closing-tag-of-an-xmldocument-in-c-net-1-1">StackOverflow question</a>, I tried the setting the <code>IsEmpty</code> property to <code>false</code> like so.</p>
  
  <pre class="lang-cs prettyprint-override"><code>var imgElements = finalHtmlDoc.SelectNodes("//*[local-name()=\"img\"]").OfType&lt;XmlElement&gt;();
  foreach (var element in imgElements)
  {
      element.IsEmpty = false;
  }
  </code></pre>
  
  <p>However that resulted in <code>&lt;img /&gt;</code> becoming <code>&lt;img&gt;&lt;/img&gt;</code>. Also, as a hack I also tried changing the <code>OuterXml</code> property directly however that doesn't work (didn't expect it to).</p>
  
  <p><strong>Question</strong></p>
  
  <p>Can you remove the self-closing tags from <code>XmlDocument</code>? I <em>honestly</em> do not think there is, as it would then be invalid xml (no closing tag), however thought I would throw the question out the community.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I ended up fixing the HTML string after exporting from the <code>XmlDocument</code> using a regular expression (written in the wonderful <a href="http://www.regexbuddy.com/" rel="nofollow noreferrer">RegexBuddy</a>). </p>
  
  <pre><code>    var fixHtmlRegex = new Regex("&lt;(?&lt;tag&gt;meta|img|br)(?&lt;attributes&gt;.*?)/&gt;", RegexOptions.IgnoreCase | RegexOptions.Multiline);
      return fixHtmlRegex.Replace(htmlStringBuilder.ToString(), "&lt;$1$2&gt;");
  </code></pre>
  
  <p>It cleared many errors from the validation pass and allow me to focus on the real compatibility problems.</p>