Friday, December 01, 2006

Getting UTF-8 Encoding with XMLTextWriter.

One of our web-service we developed has a rather unique parameter: a well-formed XML document passed in a string format. Or, to put it in another way, a string parameter whose output written out in a file will become a well-formed XML document. There a variety of reasons for doing this, instead of say using an XmlDocument type, but that's really not important.

This presents an interesting problem: how DO you create an XML document and convert it into a string, hopefully without writing too much code?

As it turns out: not easy. We started out doing it the hard way: string concatenation. Boy, talk about doing things the hard way. Mal-formed XML, slow performance, etc. Yup, all the potential problems hit us one time or another.

Next, we moved to using StringBuilder. Performs better, but doesn't remove the problems of properly-formed XML.

Then, we improved to using XMLDocument. Finally, we're getting somewhere. But the solution is a little bit overkill, due to the fact we do not need to manipulate the XML document in any way before converting it into string.

Then, I stumbled upon using XMLWriter and StringWriter. Initially, I gave XMLWriter a pass because I mistakenly believed it can only be used to write to a file, and not to memory. Well, with StringWriter, you can. Problem solved!

Well, not quite. It turns out the StringWriter encoding is set to UTF-16, and there's no way to change it. Bummer.

In the end, I found the solution: use XMLTextWriter, MemoryStream and StreamReader. All this just to get the encoding just the way you want it. The solution is less elegant, but it IS less code than the rest of the solution mentioned that doesn't use XMLTextWriter, and it works. Sometimes, you just have to take some compromise. I know I'll be happier with this solution than the others. :)

My Hotmail account is now 1GB

Ah, I still remember not too long ago, my Hotmail account is just a measly 2 MEGABYTES. Well, some time this year, it became a 25MB account, still measly compared to GMail or even Yahoo! Mail, but literally ten time more than I had since I first created this account.

Finally, it is now 1GB. Great! More than enough space to keep my spam from blowing up my account. Wish it doesn't take so long, since Gmail is now pushing past the 2.5GB limit. On the other hand, who really need that much space anyway? Even with the amount of spam and email I'm getting, I'm still using only a small percentage of the total.

However, someone DID find some use for all those space. Enter GMail Spaces, an extension for FireFox. I have not used it yet, but it reminds me of those times where the only one way to bring large files home is by splitting it and sending it to our email by attachment.

Thursday, November 30, 2006

New post: Finally.

A month since my last post, thanks to the troubles of a faulty broadband connection. Actually, the connection was fixed a couple of days after my last post, however it became a major factor in posting procrastination. I will post more on the solution to my broadband problem later.

For now, this post is just to kick-start my blogging habit again. Hopefully, nothing major will stop me from blogging again.

Monday, October 30, 2006

ASP.NET: Adaptive Rendering Model

If you are used to viewing ASP.NET pages on different browsers, you would noticed how some pages looked different on IE as opposed to say Firefox. Or as sometimes it happens, a page would look fine on IE but not on any other browser.

I originally had thought this is basically a screwup on IE being more lenient on some HTML standards, and thus are able to look just fine with the rendered HTML from the ASP.NET pages.

Apparently, that is not entirely true. Certainly not in the way I described at least.

I recently discovered that ASP.NET actually render HTML 4.0-compliant HTML for IE, and HTML 3.2-compliant HTML for other browsers. This is the main reason why there is such a difference between different browsers.

Read more about this from Scott Michell's article on the subject.

BTW, this behaviour is noted for ASP.NET 1.1. I have no clue if the same is true for ASP.NET 2.0

Broadband Blues

Gotta love my broadband connection this past week. Last weekend, I finally managed to get to a website without timing out. Then, I found out that downloading files are lightning fast. Oh great, so my file downloading speed are just fine and dandy, just that getting to the files through the websites are taking forever. -_-

I also decided to call the ISP support to get an update on my connectivity issues. Took a little longer to get through, being the weekend, but after about 10 minutes I got someone. Gave my report ID to the guy and waited for the response.

Then he gave me the bad news: they have escalated this issue to the next level, and they have assigned someone to look at it, but it is still in progress, because of a number of excuses like understaffed and the festive season. So, hopefully someone will continue to look into it on Monday.

I basically intepreted it as this: yeah, we suck at getting the job done, but hey, you're getting free support here, since that's what you paid for, you have to live with it. Technically, they're right, but since I still have to pay them monthly regardless of bad connections, that's not how i think about it. -_-

I really hope the business package get way better support than this, because if they are relying on the Internet for their business, they are going to lose a lot of money from the past few days.

Friday, October 27, 2006

My broadband connection is slower than dialup.

It has been like this since last Sunday. There was a freak thunderstorm that day, where the road leading to my housing area was flooded for a short period. I'm not surprised if it somehow cause the connection slowdown.

Right now, it is almost impossible to surf the net, even the local content. Heck, I can't surf the web page of my ISP, and if I can't go there, I can't go anywhere!

Anyway, I've already made my report to the support centre, though I don't expect them to solve the problem anytime soon. I have this  impression that the call centre support team has a huge communication barrier with the ones handling the hardware connection of the broadband. This was previously vindicated because I once had my account transferred to another line, but the physical line hookup to the switch was not done until two weeks later.

Thank god for office connection...

Wednesday, October 18, 2006

Testing some other features of Live Writer

Trying something out here: the Insert Picture in Live Writer. Wonder how it will look? Especially considering the fact I did not link this picture on any site. If so, why the heck did it let me insert it with no link? Oh wait, when I tried publishing, Live Writer just told me that this blog does not support image uploading, and I should try to upload the image through FTP to somewhere. Not bad! Now I just need to find a proper image hosting site.

One other thing: Live Writer does not support Blogger Beta's labels. Too bad, it is something that Blogger finally has for managing categories of posts. Oh well, it just means that I have to occasionally log in to Blogger and use their editor to add in the labels later. One small compromise in the grand scheme of things. I don't think I can blog consistently with writer.

P.S. I don't know why, but I noticed my spelling just deteriorates while typing on my laptop. I guess it's due to the keyboard sensitivity and spacing. And I have to use this most of the time too. -_- Thank god for spell checker on Live Writer.