title: .NET XML Serialization without <?xml> text declaration
body: <p>I'm trying to generate XML like this:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE APIRequest SYSTEM
  "https://url"&gt;
  &lt;APIRequest&gt;
    &lt;Head&gt;
        &lt;Key&gt;123&lt;/Key&gt;
    &lt;/Head&gt;
    &lt;ObjectClass&gt;
      &lt;Field&gt;Value&lt;/Field
    &lt;/ObjectClass&gt;
  &lt;/APIRequest&gt;
  </code></pre>
  
  <p>I have a class (ObjectClass) decorated with XMLSerialization attributes like this:</p>
  
  <pre><code>[XmlRoot("ObjectClass")]
  public class ObjectClass
  {
      [XmlElement("Field")]
      public string Field { get; set; }
  }
  </code></pre>
  
  <p>And my really hacky intuitive thought to just get this working is to do this when I serialize:</p>
  
  <pre><code>ObjectClass inst = new ObjectClass();
  XmlSerializer serializer = new XmlSerializer(inst.GetType(), "");
  
  StringWriter w = new StringWriter();
  w.WriteLine(@"&lt;?xml version=""1.0""?&gt;");
  w.WriteLine("&lt;!DOCTYPE APIRequest SYSTEM");
  w.WriteLine(@"""https://url""&gt;");
  w.WriteLine("&lt;APIRequest&gt;");
  w.WriteLine("&lt;Head&gt;");
  w.WriteLine(@"&lt;Field&gt;Value&lt;/Field&gt;");
  w.WriteLine(@"&lt;/Head&gt;");
  
  XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
  ns.Add("", ""); 
  serializer.Serialize(w, inst, ns);
  
  w.WriteLine("&lt;/APIRequest&gt;");
  </code></pre>
  
  <p>However, this generates XML like this:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE APIRequest SYSTEM
  "https://url"&gt;
  &lt;APIRequest&gt;
    &lt;Head&gt;
        &lt;Key&gt;123&lt;/Key&gt;
    &lt;/Head&gt;
    &lt;?xml version="1.0" encoding="utf-16"?&gt;
    &lt;ObjectClass&gt;
      &lt;Field&gt;Value&lt;/Field&gt;
    &lt;/ObjectClass&gt;
  &lt;/APIRequest&gt;
  </code></pre>
  
  <p>i.e. the serialize statement is automatically adding a &lt;?xml text declaration.</p>
  
  <p>I know I'm attacking this wrong so can someone point me in the right direction?</p>
  
  <p>As a note, I don't think it will make practical sense to just make an APIRequest class with an ObjectClass in it (because there are say 20 different types of ObjectClass that each needs this boilerplate around them) but correct me if I'm wrong.</p>