473,372 Members | 980 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,372 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 7926
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 cant 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 £
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.