473,410 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

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 7931
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robert Zierhofer | last post by:
hi there, it seems as if i can´t convert the euro and pound sign to their html equivalents. i tried eregi_replace("€", "&euro;", $haystack); eregi_replace("£", "&pound;", $haystack); as...
4
by: ben | last post by:
Hi all, I have a simple PHP page that takes values from a form and puts them in a database (MySQL). The code is in a file test.php, which I have typed in at the bottom of this post (please...
6
by: Anthony | last post by:
When using StreamReader/Writer to process an input text file to an output text file the pound signs (£) simply disappear. Sample code: StreamReader sr = new StreamReader("input.txt");...
7
by: kingski | last post by:
Any idea about this ? http://www.developerfusion.co.uk/forums/thread/114379/#114379 "Can any one help me as i am building a shopping cart and it supports multiple currencies but while sending...
4
by: monomaniac21 | last post by:
hi im outputting text from a db and where a £ sign has been entered a ? character appears instead which i cant seem to get rid of with a simple str_replace. is their a way to get rid of it? and...
2
by: Per Rasmussen | last post by:
When I use a StreamReader to read lines from a file, it seems to skip some "special" characters like ?, æ, ø and å. How do I prevent it from doing this? I know it works if the text file is in...
1
by: watcher00 | last post by:
every time i try to print "£" i get "ú" instead This print("£"); produces ú rather than £ how can i change this?
5
by: ramaswamynanda | last post by:
Hello, I have a currency field on my form. The default formats for this field are dollar, euro. There is no pound symbol.....How do i put in a currency format, having the pound sign. Any help...
4
by: jaems | last post by:
my code <font size="2">Approx </font>&nbsp;£&nbsp; which I intend to display as: Approx £ Displays as Approx £
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.