I'm trying to serialize an object I have to an XmlDocument (which is then saved to a file). The problem is that some hex characters seem to be placed in front of the actual xml when I view the file in hex representation (using UltraEdit). These characters are being read by another program I have, which is causing issues.
The first line contains this (notice leading 
):
<?xml version="1.0" encoding="utf-8"?>
I'm not sure why I'm getting those characters.
The code that creates the document:
' At this point, I have an object called newObj that has mostly string/integer fields.
' It is non-null as populated with the correct data.
xd = New XmlDocument
Dim xs As XmlSerializer = New XmlSerializer(GetType(MyObj))
Dim result As String = String.Empty
Using ms As MemoryStream = New MemoryStream()
xs.Serialize(ms, newObj)
ms.Position = 0
result = New StreamReader(ms).ReadToEnd()
End Using
xd.LoadXml(result)
And then I create the file here:
Using xw As XmlTextWriter = New XmlTextWriter(myFile, New UTF8Encoding(True))
xw.Formatting = Formatting.Indented
xw.Indentation = 1
xw.IndentChar = " "
xd.Save(xw)
End Using