title: C#: How to remove a line in XML file?
body: <p>May be it is a silly question, but I need to remove the top line in my XML file.
  This is the line:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
  </code></pre>
  
  <p>When doing this</p>
  
  <pre><code>string xmlToSend = ClassToXML(myObject);
  
  string newString= xmlToSend.Replace("&lt;?xml version=\"1.0\" encoding=\"utf - 16\"?&gt;", string.Empty);
  </code></pre>
  
  <p>nothing happens.</p>
  
  <p>The file still has the line there.</p>
  
  <p>I have a method that serializes my object into an XML string and return that string. How do I remove XML declaration from that string?</p>
  
  <pre><code>private string ClassToXML(Object classObject)
  {
      var myString = new System.IO.StringWriter();
      var serializer = new XmlSerializer(classObject.GetType());
      System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb, new System.Xml.XmlWriterSettings()
      {
          OmitXmlDeclaration = true,
          ConformanceLevel = System.Xml.ConformanceLevel.Auto,
          Indent = true
      });
  
      //serializer.Serialize(myString, classObject);
      serializer.Serialize(xw, classObject);
  
      return myString.ToString();
  
  }
  </code></pre>
  
  <p>What am I missing?</p>