May be it is a silly question, but I need to remove the top line in my XML file. This is the line:
<?xml version="1.0" encoding="utf-16"?>
When doing this
string xmlToSend = ClassToXML(myObject);
string newString= xmlToSend.Replace("<?xml version=\"1.0\" encoding=\"utf - 16\"?>", string.Empty);
nothing happens.
The file still has the line there.
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?
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();
}
What am I missing?
 
     
     
    