Tuesday 8 September 2009

Trying to add named entities support to XHTML

This morning I checked my email then took some photos in the garden.

I did some more work on my website the rest of the morning and afternoon, still trying to get Wordpress and Google site search to work.

One of the things I was looking at was if it was possible to add named entities support to XML/XHTML. In my googling I came across this article The perils of using XHTML properly, which while it doesn't cover what I was looking for, is an interesting read. I was particularly interested in the bit about adding stylesheets correctly:
<?xml-stylesheet href="stylesheet1.css" type="text/css"?>
<?xml-stylesheet href="#stylesheet2" type="text/css"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>XML stylesheet declaration</title>
<style type="text/css" id="stylesheet2">
@import “stylesheet2.css";
</style>
</head>
I'm using the same syntax as I would in an HTML page, and it doesn't seem to cause any problems:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>XML stylesheet declaration</title>
<link rel="stylesheet" href="./stylesheet1.css" type="text/css" />
<link rel="stylesheet" href="./stylesheet2.css" type="text/css" />
</head>

After dinner I played on the sword thing on Wii Sports Resort again, still haven't completed Reverse Volcano yet.

After that I tried out an example for extending XHTML, in the hope that it would be possible to extend XHTML to include common named entities. However, while the browser would render the example (served as application/xhtml+xml or application/xml), using Fiddler I could see that the browser didn't make any attempt to access the custom schema. This meant that while I could try and add named entities to a schema, they wouldn't be respected by the browser as the browser wouldn't attempt to read the schema, and so knew nothing about them.

Still, it was interesting to see that page rendered in IE7 as html rather than xml. The example page doesn't have a doctype declaration, in IE7 this put the browser in quirks mode (BackCompat), but in Firefox the page was rendered in standards mode (CSS1Compat).

After that, I read an article on using a custom DTD. Downloading the example from there, I found that the page would render in standards mode (CSS1Compat) in both Firefox and Internet Explorer 7, however neither browser requested the DTD so I'm guessing if you tried to use this method to add named entites support to xhtml it wouldn't work.

I tried the other method suggested in that article of writing the entity declarations inline in the doctype declaration of the page. This worked in Firefox, and allowed me to use &nbsp;. In IE it printed the ]> characters, like the article says happens.

Strangely, it seemed that IE wasn't using an xml parser to parse the page, but was parsing it as html. I added <> to the page, Firefox complained about the invalid xml, but IE didn't. The page was definitely being sent to IE7 with the header Content-Type: application/xml; charset=utf-8 though (I checked in Fiddler).

The weather was sunny and quite windy most of today. It clouded over in the evening, and there wasn't a sunset to be seen.

Food
Breakfast: Lemon marmalade toast sandwich; cup o' tea.
Lunch: ½ Cheese toastie; Packet of Barbecue flavour crisps; some Cherry tomatoes; banana; clementine; 2x plums; Slice of Yoghurt and raisin cake that McRad made a few days ago; Chocolate Orange Montana; cup o' tea.
Dinner: Slice of pepperoni pizza; chips; salad. Pudding was a Slice of Yoghurt and raisin cake that McRad made a few days ago with instant custard that had the consistency of water. Coffee; Piece of Tesco's cheapo chocolate.

No comments: