all groups > dotnet xml > february 2004 >
You're in the

dotnet xml

group:

how to write unicode using XMLWriter?


how to write unicode using XMLWriter? Linda Chen
2/25/2004 11:03:52 AM
dotnet xml:
I need to write some unicode symbols such as degree symbol
(for example 36=B0) by using XMLTextWrite but couldn't make=20
it work. I found the degree char in unicode is '\u030A'=20
and here is my sample code:

char myChar =3D '\u030A';
string myString =3D "36" + myChar.ToString();
myWriter.WriteString(myString);

it doesn't work.

Anyone ideas?

Thanks.

Re: how to write unicode using XMLWriter? Derek Harmon
2/25/2004 9:58:31 PM
[quoted text, click to view]

Your code looks fine, just verify that when you create the XmlTextWriter
that you do so with a Unicode encoding, for instance,

XmlTextWriter myWriter = new XmlTextWriter( fileStream,
new System.Text.UnicodeEncoding( ) );

If you want to hide the Byte Order Mark (BOM) then make sure that you
use the parameterized UnicodeEncoding contructor:

XmlTextWriter myWriter = new XmlTextWriter( fileStream,
new System.Text.UnicodeEncoding( false, false) );

If on the other hand, you're already doing this, then perhaps you are not
seeing the degree symbol because of the font used by your text editor.
If you turn on the Byte Order Mark,

XmlTextWriter myWriter = new XmlTextWriter( fileStream,
new System.Text.UnicodeEncoding( false, true) );

Then you should be able to load the resulting Unicode XML file into
Microsoft Word (it will auto-detect the encoding if a BOM is present)
as Unicode text. Next, change the Font to "Lucida Sans Unicode,"
and you should see the degree symbol (instead of the rectangle
that indicates that code point doesn't have a glyph in Windows'
current code page).


Derek Harmon

AddThis Social Bookmark Button