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

Developer Day

Tuesday, May 02, 2006
Having resolved to blog more, and failing miserably, I've finally overcome the inertia :-)

Developer Day is a nice little developer conference run by the UK .NET user group community. I'm talking on Windows Workflow Foundation, which I've been tinkering with since last years PDC. I'll probably post the slides and sample code on here as I get it working.

And for Martin, who avidly reads my writings, today I'm feeling mostly perky.

# posted by James @ 3:29 PM   3 comments
This page is powered by Blogger. Isn't yours?