Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Omitting XML processing instruction when serializing an object

Tags:

I'm serializing an object in a C# VS2003 / .Net 1.1 application. I need it serialized without the processing instruction, however. The XmlSerializer class puts out something like this:

<?xml version="1.0" encoding="utf-16" ?> 
<MyObject>
    <Property1>Data</Property1>
    <Property2>More Data</Property2>
</MyObject>

Is there any way to get something like the following, without processing the resulting text to remove the tag?

<MyObject>
    <Property1>Data</Property1>
    <Property2>More Data</Property2>
</MyObject>

For those that are curious, my code looks like this...

XmlSerializer serializer = new XmlSerializer(typeof(MyObject));
StringBuilder builder = new StringBuilder();

using ( TextWriter stringWriter = new StringWriter(builder) )
{
    serializer.Serialize(stringWriter, comments);
    return builder.ToString();
}