M
Mike Murray
Hi I have the following issue.
I have a character that is return by a SQL Server database "É" to be
precise, the issue is that when I store character in a .net string
variable my understanding is that it converts it to UTF-16
automatically. I've seen a lot of quotes saying "All String datatype
variables in .NET are UTF-16 encoded". The thing is that I want to
write this character to a XML file in UTF-8 encoded format instead. How
do I go about doing this?
Right now I've tried the following scenerio's (all in VB.Net) when
writing to my XmlTextWriter object:
1) Encoding the string into UTF-8 bytes, then placing the string into
a Stream Reader and then from there reading the stream into the
XmlTextWriter
Dim utf8 As New UTF8Encoding(True)
Dim fNameBytes As Byte() = utf8.GetBytes(strFName)
Dim stmFName As StreamReader = _
New StreamReader( New MemoryStream( fNameBytes ), utf8)
....
EFSXml_UserInfo.WriteAttributeString("firstname",
stmFName.ReadToEnd() )
2) I've also tried the code below:
Dim utf8 As New UTF8Encoding(True)
Dim xtrFName As XmlTextReader = _
New XmlTextReader(New StringReader(strFName))
Dim msFName As MemoryStream = New MemoryStream()
Dim xtwFName As XmlTextWriter = New XmlTextWriter(msFName, utf8)
xtwFName.WriteNode(xtrFName, false)
xtwFName.Flush()
msFName.Position = 0
Dim srFName As StreamReader = New StreamReader(msFName)
....
EFSXml_UserInfo.WriteAttributeString("firstname", srFName
..ReadToEnd() )
Neither of the 2 result in encoding the string correctly, can someone
please help me out, I've spend close to 2 days trying to figure this
stupid thing out.
Thanks,
Mike Murray
I have a character that is return by a SQL Server database "É" to be
precise, the issue is that when I store character in a .net string
variable my understanding is that it converts it to UTF-16
automatically. I've seen a lot of quotes saying "All String datatype
variables in .NET are UTF-16 encoded". The thing is that I want to
write this character to a XML file in UTF-8 encoded format instead. How
do I go about doing this?
Right now I've tried the following scenerio's (all in VB.Net) when
writing to my XmlTextWriter object:
1) Encoding the string into UTF-8 bytes, then placing the string into
a Stream Reader and then from there reading the stream into the
XmlTextWriter
Dim utf8 As New UTF8Encoding(True)
Dim fNameBytes As Byte() = utf8.GetBytes(strFName)
Dim stmFName As StreamReader = _
New StreamReader( New MemoryStream( fNameBytes ), utf8)
....
EFSXml_UserInfo.WriteAttributeString("firstname",
stmFName.ReadToEnd() )
2) I've also tried the code below:
Dim utf8 As New UTF8Encoding(True)
Dim xtrFName As XmlTextReader = _
New XmlTextReader(New StringReader(strFName))
Dim msFName As MemoryStream = New MemoryStream()
Dim xtwFName As XmlTextWriter = New XmlTextWriter(msFName, utf8)
xtwFName.WriteNode(xtrFName, false)
xtwFName.Flush()
msFName.Position = 0
Dim srFName As StreamReader = New StreamReader(msFName)
....
EFSXml_UserInfo.WriteAttributeString("firstname", srFName
..ReadToEnd() )
Neither of the 2 result in encoding the string correctly, can someone
please help me out, I've spend close to 2 days trying to figure this
stupid thing out.
Thanks,
Mike Murray