Home All Groups Group Topic Archive Search About

memory stream, xmltextwriter issue

Author
30 Mar 2006 9:48 PM
hharry
hi all

i have the following class:

<Serializable()> _
Public Class MVR_Inputs
    Public FirstName As String
    Public MiddleName As String
    Public LastName As String
    Public Suffix As String
    Public Dob As String
    Public Ssn As String
    Public Gender As String
    Public DriversLicenseNumber As String
    Public DriversLicenseState As String
    Public YouthCheck As String
    Public CustomerBatchID As String
    Public CustomerOrderID As String
    Public TestMode As Boolean = False
    Public TimePeriod As Integer
    Public RequestType As String
End Class

which i attempt to serialize by using this code:

Dim objMemStrm As MemoryStream
Dim objXmlWriter As XmlTextWriter
Dim objXmlSerializer As XmlSerializer
Dim byteArray() As Byte

objMemStrm = New MemoryStream
objXmlWriter = New XmlTextWriter(objMemStrm, Encoding.UTF8)
objXmlSerializer = New XmlSerializer(oSubject.GetType())
objXmlSerializer.Serialize(objXmlWriter, oSubject)
byteArray = objMemStrm.GetBuffer
sSerializedReq = System.Text.Encoding.UTF8.GetString(byteArray)

the serialization works fine, except that the first character of of
sSerializedReq is always ASCII character 239 - an i with 2 small dots
on top

any ideas ?

thanks in advance

Author
31 Mar 2006 12:06 AM
AlanT
The characters are the Byte Order Mark (BOM)


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_42jv.asp

which are emitted when using the default UTF8 encoding

To prevent them being emitted use an instance of the UTF8 Encoding that
does not emit them

i.e.
   objXmlWriter = New XmlTextWriter(objMemStrm, New
System.Text.UTF8Encoding(False))


hth,
Alan.