llor.nu Player Stats

Well it looks like my Ajax Hello World will have to go on hold a bit longer. I've started playing a bizarrely addictive, online, multiplayer, Ajax powered board game over at llor.nu.

There are still a few quirks to be ironed out, but after a few days play, I've started to build up my own real estate empire. Yes, it is I, Mr Scruff, currently languishing in 43rd place. Perhaps you've paid me a few units of the nameless currency when you stayed in one of my lovely hotels?

How many childNodes does an empty div element have?

Update 2: 18th October 2005

Since this was published as a bug report on QuirksMode many commenters have pointed out that I got it wrong due to a misunderstanding of the XHTML spec. Having been pointed in the right direction by you all, I think I now understand the problem thanks. My original test page is served with a Content-Type HTTP response header of "text/html". According to section 5.1 of the XHTML 1.0 Recommmendation:

XHTML Documents which follow the guidelines set forth in Appendix C, "HTML Compatibility Guidelines" may be labeled with the Internet Media Type "text/html" RFC2854, as they are compatible with most HTML browsers

So I'd have to follow the guidelines given in Appendix C, or a conforming browser could justifiably be upset. Now section C.3 says:

Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph) do not use the minimized form (e.g. use <p> </p> and not <p />).

And of course, according to the DTD used by my test page, a div element does not have a content model that is EMPTY. So indeed, the browsers get justifiably upset.

However, section 5.1 of the spec seems to say it would be acceptable to use the minimized form of the empty div element if I served my page with a Content-Type HTTP response header of "application/xhtml+xml":

Those documents, and any other document conforming to this specification, may also be labeled with the Internet Media Type "application/xhtml+xml" as defined in RFC3236.

So I have an identical copy of my test page served as "application/xhtml+xml" which demonstrates that the "bug" does indeed vanish in FireFox and Opera when served like this. Unfortunately, the page cannot be viewed by IE6 when served with this MIME type. Instead, IE provides a "File download" dialog instead of rendering the page.

Which I suppose boils this page down to:

Don't use the minimized form of an empty div element because you have to serve your page as "text/html" in order to keep IE happy

My original post follows.

Update: 18th October 2005

Created a more concise test page and submitted a bug report to QuirksMode where it has now been published in the bug reports list. Thanks to Peter-Paul Koch for maintaining such an excellent resource.

How many childNodes does an empty div element have?

Or to put it more explicitly:

Given this snippet of valid markup taken from a valid XHTML page...

<div id="test" />

...what does this javascript statement evaluate as?


I would expect most rational people to say 0. But most rational people would be wrong just like I was. The answer is actually 4. Or 9. Or 11. As you can see here, here and here. Try it for yourself by viewing the test page

Odd. It seems that the various different browsers are actually mistaking childNodes of the test div with the childNodes of the body as we can see from the output of the test page when it dumps the content of the testDiv.childNodes array. The various different answers are as a result of differences between the handling of text nodes by the different browsers. IE doesn't seem to have any text nodes at all in its childNodes array; Opera has 2 line feeds more than Firefox does at the end of its array.

There is a simple workaround for this quirk. For a mere 4 extra bytes we can write the empty div the long way like so.

<div id="test"></div>

Now the browsers all agree with most rational people. Which makes a nice change. You can see the results here, here and here. Try it for yourself by viewing the test page.

Freeview Media PC Part 1

Hoorah. Finally. Some progress on my DIY Media PC Project. Here's a quick screen shot:

Mythtv on ubuntu

( Note for non UK readers: It honestly doesn't rain all the time up north. That's why there's a big exclamation mark in a red triangle. He's surprised. )

Anyway, this has been quite an experience. Thought I'd share it and maybe some people will read this and decide to put their time towards something more productive.

As you can see, I've now managed to get to the point where I can tune into a freeview channel and watch it stream through mplayer. Not earth shattering but it's taken long enough to get here. Next step is to get mythtv up and running. The aim is to use this thing as an appliance rather than as a PC that happens to be able to show freeview channels when you type the correct series of incantations at a terminal. It needs to be useable with just the remote control and the keyboard can go behind the sofa until the inevitable emergency happens.

So why's it taken so long? I thought it would be easy. But most things that I think will take a few hours seem to end up taking weeks or months. Like that time I thought I'd see if I could write a game in QBasic. About four years later I got to the point where I decided that yes, I could write a game in QBasic.

With this Media PC saga, I had to return 3 faulty DVB cards of various makes to ebuyer (great service from them) before finally getting a working Hauppauge WinTV-Nova-t PCI Freeview Receiver.

I say working, but it was still dropping frames all over the place and the audio was mostly ear piercing squeeks and pops. But there was definitely something happening so I kept the card. Looks like that was a good idea as it turned out to be a software problem.

The drivers and software that accompany the Nova-t are, unsurprisingly, for Windows XP. I always planned to get the Media PC running mythtv on Linux of some flavour. But not being much of a Linux expert, I thought I'd test all the hardware on Windows first, seeing as that's what is officially supported.

Well installation was easy enough, but the Hauppauge software was terrible. Just peruse the comments left by buyers to get some flavour of the problems. I tried downloading the latest drivers, including the German ones from the German website. Still dropping frames. I tried using different software to watch and record the TV. MediaPortal was the best of these but chewed up over 300MB of RAM. Just to show the front page menu. Yikes. That'd be the .NET effect? Still dropping frames there too. So I gave up for a few weeks.

Then a friend suggested I take the Nova-T round to his house and we try it out on his KnoppMyth box. In just a few hours of fiddling we had it working perfectly. Great - no hardware problems with the Nova-t at least. Didn't take us long to decide to wipe my box to get rid of Windows (and the only copy of a few digital photos - oops) and try KnoppMyth there. Of course, this didn't go entirely smoothly either. KnoppMyth didn't like my ATI graphics card. I'm new to Linux and didn't know that just choosing the cheapest fanless graphics card is not a good idea if it happens to be made by ATI. Well we all learn from our mistakes so I won't be doing that again. Before giving up on the ATI card, I switched distros from KnoppMyth to Ubuntu which I like a lot. It couldn't handle the ATI card either, so I swapped in an old Kyro II board from the Dusty Cupboard of Computer Parts That May, One Day, Be Useful. That works a treat with the generic VESA drivers, but I had to disconnect the noisy fan. No problems yet <touch wood>

Once I could see what I was doing, it was basically just a case of following the excellent instructions given in the Ubuntu Wiki. And now I can actually watch telly on my Media PC, without any dropped frames or hideous squeeks. A mere 3 months after I bought the parts and first put them together. Now, I wonder what the weather will be like down here tomorrow...