469,292 Members | 1,318 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,292 developers. It's quick & easy.

Pound sign () in XML

Hi there,
I am using the .Net XML Serialization classes to create XML
strings. This has been working fine up until the point that one of the
strings contained a pound sterling symbol. The application that is
processing the output complains about the character. Both the strings and
the application are using UTF-8. If you view the text in Notepad the pound
symbol looks fine, but if you view the hex, there is a character preceding
the pound sign like so: £. Why does it not get converted to £ ?
Nov 12 '05 #1
5 7565
Waldy wrote:
I am using the .Net XML Serialization classes to create XML
strings. This has been working fine up until the point that one of the
strings contained a pound sterling symbol. The application that is
processing the output complains about the character. Both the strings and
the application are using UTF-8. If you view the text in Notepad the pound
symbol looks fine, but if you view the hex, there is a character preceding
the pound sign like so: £.
This actually looks like UTF-16. Strings in .NET are always UTF-16 encoded.
Why does it not get converted to £ ?

What for? XML is capable to contain any character from any language in
the whole world, what's the point to escape characters increasing XML
document size? You better fix your encoding issue instead.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #2

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
This actually looks like UTF-16. Strings in .NET are always UTF-16
encoded.


So even though I am using a string writer encoded to UTF-8, the fact that I
assign it to a string is enough to set it back to UTF-16?

ie:

public override string GetData()

{

string strData = null;

....

XmlSerializer serialiser = new XmlSerializer(typeof(@event));

TextWriter textWriter = new
StringWriterWithEncoding(System.Text.Encoding.UTF8 );

XmlWriter writer = new XmlTextWriter(textWriter);

serialiser.Serialize(writer, tp1Event);

strData = textWriter.ToString();

return strData;

}


Nov 12 '05 #3
Waldy wrote:
So even though I am using a string writer encoded to UTF-8, the fact that I
assign it to a string is enough to set it back to UTF-16?
Strings are always in UTF-16. And so you can't change encoding for
StringWriter class - it's always UTF-16.
StringWriterWithEncoding(System.Text.Encoding.UTF8 );


AFAIR this class is a particlular hack which helps to produce UTF-16
encoded string containing different encoding in XML declaration. I
wouldn't recommend using it, just google for it to see why.
If you need other than UTF-16 encoding, use MemoryStream instead.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #4

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
If you need other than UTF-16 encoding, use MemoryStream instead.


And put it into a byte array instead of a string?
Nov 12 '05 #5
Waldy wrote:
And put it into a byte array instead of a string?


Yep. Or leave it in UTF-16 and encode to UTF-8 only when serializing to
file or whatever.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Robert Zierhofer | last post: by
4 posts views Thread by ben | last post: by
6 posts views Thread by Anthony | last post: by
7 posts views Thread by kingski | last post: by
4 posts views Thread by monomaniac21 | last post: by
2 posts views Thread by Per Rasmussen | last post: by
1 post views Thread by watcher00 | last post: by
4 posts views Thread by jaems | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.