M
muesliflakes
I have the following utility function to serialize my object to XML
public static string WriteToString( object o, Type type )
{
XmlSerializer serializer = new XmlSerializer( type );
StringWriter output = new StringWriter( );
serializer.Serialize(output, o );
return output.ToString( );
}
This method works great, except for one issue. Because the underlying
data is a string (unicode), the serialization process automatically
writes <?xml version='1.0' encoding='utf-16'?> out and there is no way
with strings of changing this encoding type.
Now if I was writing to a file, I would have no issues as StreamWriter
which is used for files supports an Encoding enumeration. But I don't
want to write the xml directly to a SqlServer stored procedure, but
the SP fails because it wants to see utf-8, now if I manually the
utf-16 to utf-8 (I know that the underlying data really is utf-16),
then SqlServer has no problems.
I want to find out how I can serialize an object to string, but change
the encoding type.
Cheers Dave
public static string WriteToString( object o, Type type )
{
XmlSerializer serializer = new XmlSerializer( type );
StringWriter output = new StringWriter( );
serializer.Serialize(output, o );
return output.ToString( );
}
This method works great, except for one issue. Because the underlying
data is a string (unicode), the serialization process automatically
writes <?xml version='1.0' encoding='utf-16'?> out and there is no way
with strings of changing this encoding type.
Now if I was writing to a file, I would have no issues as StreamWriter
which is used for files supports an Encoding enumeration. But I don't
want to write the xml directly to a SqlServer stored procedure, but
the SP fails because it wants to see utf-8, now if I manually the
utf-16 to utf-8 (I know that the underlying data really is utf-16),
then SqlServer has no problems.
I want to find out how I can serialize an object to string, but change
the encoding type.
Cheers Dave