Search code examples
c#serializationdatacontractserializer

DataContractSerializer - Ignore XML Declaration


How can I get the DataContractSerializer to ignore the xml declaration in xml I want to deserialize?

I want to avoid reading all bytes from stream and removing the declaration from the string.


Solution

  • The DataContractSerializer will not serialize the XML declaration, as you do will not have a property for it on the class you are deserializing to.

    Regardless - it needs to read the whole file, so the declaration will be read as well.

    Why are you trying to remove it like this?