Re: Sql server to xml string with encoding

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/22/04


Date: Tue, 22 Jun 2004 14:38:21 +0100

Urban Andersson <anderssonurban@hotmail.com> wrote:
> But the data is stored in ISO-8859-9 in the database. Is it not correct the
> to set the stream to ISO-8859-9 so that the data will be converted to that
> encoding when writing to the stream instead of UTF-8 wich the data is not?
> It seems to me that the WriteXml method writes UTF-8 to the stream instead
> of ISO-8859-9?

It doesn't matter how the data is stored in the database - by the time
it's been fetched from the database, it's just Unicode text, assuming
you've got it in text fields in the database. If it's a text field, the
data is just text data. It doesn't intrinsically have an encoding -
that's an implementation detail for storage, effectively.

See http://www.pobox.com/~skeet/csharp/unicode.html and
http://www.pobox.com/~skeet/csharp/debuggingunicode.html for more
information.

> I tried using the StringWriter but i am not able to set
> the encoding.

As I said, you need to subclass StringWriter in order to specify an
encoding. You basically override the Encoding property.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Sql server to xml string with encoding
    ... But the data is stored in ISO-8859-9 in the database. ... encoding when writing to the stream instead of UTF-8 wich the data is not? ... > Rather than writing to a MemoryStream, write to a StringWriter. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Send string to IP address
    ... "Plain hex" implies something formatted as text, but doesn't answer the question of encoding. ... There's no "just" as far as "an ASCII string" is concerned. ... Characters are not bytes and bytes are not characters. ... Normally you'd create the Writer once at the same time as you create the underlying stream, rather than every time you write some text, obviously. ...
    (comp.lang.java.programmer)
  • Re: combine serveral .txt files
    ... Open the first stream to read from ... When you've finished all the files, close the output stream. ... the files are using the same encoding. ... and the bicycle has to *want* to change. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Character semantics for filenames (was: win32 reading wide filenames (unicode))
    ... DO WITH CHARACTERS ABOVE "\xFF". ... suspect, openworks on the supplied byte stream AS IS, discregarding ... Unocode inserts hints in strings. ... encoding to perl strings by readdir and from perl strings to the OS ...
    (comp.lang.perl.misc)
  • Re: Stream and Encoding Confusion
    ... We are each writing programs to read an input file and count the number of ... a simple list that says we the program found so many of each character; ... treated as a character stream or a byte stream. ... I'm also somewhat concerned about encoding. ...
    (comp.lang.java.programmer)