Architect or Cobbler?
Good code starts with good design

XML and £ symbols

Thursday, May 04, 2006
I post quite a bit on the ASP.NET forums, and occasionally I get asked a question via private message. One I was asked with today was how to deal with the £ symbol in an XML file that has been saved in Windows. The problem here is that if you edit and save something in Windows it typically saves it with an ANSI encoding. Now ANSI encoding doesn't actually mean anything, what this actually means is that the file is saved using an ANSI standard Windows code page. For Western Europe and the USA this is typically CP1252, which is essentially the same as ISO-8859-1, except for some control characters in the range 128-152. Unfortunately this includes the Euro symbol, so you can't just say encoding="ISO-8859-1" in the xml declaration, I believe you can say encoding="windows-1252", but haven't actually tried this. Usually what I do is simply open the file in Notepad and then save it as UTF-8 using the little dropdown. What about doing it via code though? Well usually I do something like this:

StreamReader reader = new StreamReader("..\\..\\pound.xml", System.Text.Encoding.Default);
XmlDocument doc1 = new XmlDocument();
doc1.Load(reader);
XmlTextWriter tw = new XmlTextWriter("..\\..\\pound2.xml", Encoding.UTF8); 
doc1.WriteContentTo (tw);
tw.Close();
Of course if your default Windows encoding isn't CP1252 this won't work :-)

# posted by James @ 6:15 PM   3 comments Comments: Well done!
[url=http://vauqjbcy.com/jsib/beqb.html]My homepage[/url] | [url=http://tlgcpadk.com/pzyw/ksfv.html]Cool site[/url]
# posted by Anonymous Anonymous @ 10:00 PM   Nice site!
My homepage | Please visit
# posted by Anonymous Anonymous @ 10:03 PM   Well done!
http://vauqjbcy.com/jsib/beqb.html | http://vcgljvlu.com/kpqr/omsg.html
# posted by Anonymous Anonymous @ 10:03 PM   Post a Comment

<< Main blog page
This page is powered by Blogger. Isn't yours?