title: Remove p2:type="<<type>>" xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" from xml
body: <p>How to remove xmlns from all the inner nodes of the xml. I was able to remove the xmlns from the root node but still the inner node has all the xmlns in the inner node.</p>
  
  <pre><code>public class Program
  {
      public static void Main()
      {
  
          List&lt;Person&gt; students = new List&lt;Person&gt;();
  
          Student std1 = new Student() { Name="Name1", StudentId = 1};
          students.Add(std1);
  
          Student std2 = new Student() { Name = "Name2", StudentId = 2 };
          students.Add(std2);
  
          string data = students.ToList().ToXML();
      }
  }
  
  [System.Xml.Serialization.XmlInclude(typeof(Student))]
  public class Person
  {
      public string Name { get; set; }
  }
  
  public class Student : Person
  {
      public int StudentId { get; set; }
  }
  </code></pre>
  
  <p>ToXML()</p>
  
  <pre><code>public static string ToXML&lt;T&gt;(this T value)
      {
          if (value.IsNull()) return string.Empty;
  
          var xmlSerializer = new XmlSerializer(typeof(T));
          XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
          ns.Add("", "");
  
          using (var stringWriter = new StringWriter())
          {
              using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { OmitXmlDeclaration = true, Indent = false }))
              {
                  xmlSerializer.Serialize(xmlWriter, value, ns);
                  return stringWriter.ToString();
              }
          }
      }
  </code></pre>
  
  <p>Output is</p>
  
  <pre><code>&lt;ArrayOfPerson&gt;
      &lt;Person p2:type="Student" xmlns:p2="http://www.w3.org/2001/XMLSchema-instance"&gt;
          &lt;Name&gt;Name1&lt;/Name&gt;
          &lt;StudentId&gt;1&lt;/StudentId&gt;
      &lt;/Person&gt;
      &lt;Person p2:type="Student" xmlns:p2="http://www.w3.org/2001/XMLSchema-instance"&gt;
          &lt;Name&gt;Name2&lt;/Name&gt;
          &lt;StudentId&gt;2&lt;/StudentId&gt;
      &lt;/Person&gt;
  &lt;/ArrayOfPerson&gt;
  </code></pre>
  
  <p>Expected output is</p>
  
  <pre><code>&lt;ArrayOfPerson&gt;
      &lt;Person&gt;
          &lt;Name&gt;Name1&lt;/Name&gt;
          &lt;StudentId&gt;1&lt;/StudentId&gt;
      &lt;/Person&gt;
      &lt;Person&gt;
          &lt;Name&gt;Name2&lt;/Name&gt;
          &lt;StudentId&gt;2&lt;/StudentId&gt;
      &lt;/Person&gt;
  &lt;/ArrayOfPerson&gt;
  </code></pre>