title: Multiple namespaces with XmlSerializer
body: <p>This is the scenario:</p>
  
  <p>I have nested classes and need to serialize then in an xml document</p>
  
  <pre><code>[XmlRoot(Namespace="http://www.foo.bar/myschema")]
  public class root 
  {
      [XmlAttribute]
      public string version { get; set; }
  
      [XmlElement]
      public child child { get; set; }
  
      ...
  }
  
  [XmlRoot(Namespace="http://www.foo.bar/myschema")]
  public class child
  {
      [XmlElement]
      public int elemA { get; set; }
  
      [XmlElement]
      public string elemB { get; set; }
  
      ...
  }
  </code></pre>
  
  <p>I have created an method based in another example to remove additional namespaces and set a custom one:</p>
  
  <pre><code>public static void Save&lt;T&gt;(this T type, string path)
  {
      System.Xml.Serialization.XmlSerializer xs = 
          new System.Xml.Serialization.XmlSerializer(type.GetType());
  
      System.Xml.Serialization.XmlSerializerNamespaces ns = 
          new System.Xml.Serialization.XmlSerializerNamespaces();
      ns.Add("", "http://www.foo.bar/myschema");
  
      using(XmlWriter file = XmlWriter.Create(path))
      {
          xs.Serialize(file, type, ns);
      }
  }
  </code></pre>
  
  <p>And I get this code as result:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;root xmlns="http://www.foo.bar/myschema" version="2.00"&gt;
      &lt;child&gt;
          &lt;elemA&gt;1&lt;/elemA&gt;
          ...
      &lt;/child&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>But expected this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;root xmlns="http://www.foo.bar/myschema" version="2.00"&gt;
      &lt;child xmlns="http://www.foo.bar/myschema"&gt;
          &lt;elemA&gt;1&lt;/elemA&gt;
          ...
      &lt;/child&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>We must set the custom namespace declaration in both tags. Is this possible?</p>
  
  <p>Edit:</p>
  
  <p>Here is a real-world example:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;enviNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.01"&gt;
      &lt;idLote&gt;200602220000001&lt;/idLote&gt;
      &lt;NFe xmlns="http://www.portalfiscal.inf.br/nfe"&gt;
          &lt;infNFe Id="NFe31060243816719000108550000000010001234567890" versao="1.01"&gt;
          ...
          &lt;Signature xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;
          ...
      &lt;/NFe&gt;
      &lt;NFe xmlns="http://www.portalfiscal.inf.br/nfe"&gt;
          &lt;infNFe Id="NFe31060243816719000108550000000010011234567900" versao="1.01"&gt;
          ...
          &lt;Signature xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;
          ...
      &lt;/NFe&gt;
      &lt;NFe xmlns="http://www.portalfiscal.inf.br/nfe"&gt;
          &lt;infNFe Id="NFe31060243816719000108550000000010021234567916" versao="1.01"&gt;
          ...
          &lt;Signature xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;
          ...
      &lt;/NFe&gt;
  &lt;/enviNFe&gt;
  </code></pre>