title: How to remove all namespaces from XML with C#?
body: <p>I am looking for the clean, elegant and smart solution to remove namespacees from all XML elements? How would function to do that look like?</p>
  
  <p>Defined interface:</p>
  
  <pre><code>public interface IXMLUtils
  {
          string RemoveAllNamespaces(string xmlDocument);
  }
  </code></pre>
  
  <p>Sample XML to remove NS from:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
  &lt;ArrayOfInserts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;insert&gt;
      &lt;offer xmlns="http://schema.peters.com/doc_353/1/Types"&gt;0174587&lt;/offer&gt;
      &lt;type2 xmlns="http://schema.peters.com/doc_353/1/Types"&gt;014717&lt;/type2&gt;
      &lt;supplier xmlns="http://schema.peters.com/doc_353/1/Types"&gt;019172&lt;/supplier&gt;
      &lt;id_frame xmlns="http://schema.peters.com/doc_353/1/Types" /&gt;
      &lt;type3 xmlns="http://schema.peters.com/doc_353/1/Types"&gt;
        &lt;type2 /&gt;
        &lt;main&gt;false&lt;/main&gt;
      &lt;/type3&gt;
      &lt;status xmlns="http://schema.peters.com/doc_353/1/Types"&gt;Some state&lt;/status&gt;
    &lt;/insert&gt;
  &lt;/ArrayOfInserts&gt;
  </code></pre>
  
  <p>After we call RemoveAllNamespaces(xmlWithLotOfNs), we should get:</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-16"?&gt;
      &lt;ArrayOfInserts&gt;
        &lt;insert&gt;
          &lt;offer &gt;0174587&lt;/offer&gt;
          &lt;type2 &gt;014717&lt;/type2&gt;
          &lt;supplier &gt;019172&lt;/supplier&gt;
          &lt;id_frame  /&gt;
          &lt;type3 &gt;
            &lt;type2 /&gt;
            &lt;main&gt;false&lt;/main&gt;
          &lt;/type3&gt;
          &lt;status &gt;Some state&lt;/status&gt;
        &lt;/insert&gt;
      &lt;/ArrayOfInserts&gt;
  </code></pre>
  
  <p>Preffered language of solution is C# on .NET 3.5 SP1.</p>