Friday, March 9, 2007

Xpointer in firefox

pencil icon, that"s clickable to start editing the post

I haven't look at the Xpointer spec's for a long time, that's since the first one, but now I can see that there are now three recommendations since 25 March 2003:

It surprised me that the XPointer xpointer() scheme stranded as just a working draft. Before making this post i first tried out using this scheme because that was what I had used when I last used XPointer. The refence I used back then XML - in a Nutshell (first edition) is quite dated so it's about time I get an update :-).

I was pretty sure that firefox/mozilla would support XPointer, and it does support all three of them as stated on the XML in Mozilla page on Mozilla Developer Center, which is even outdated. It does not say why it's outdated and which version it relates to, but it's probably valid for FF1.5 and later. There are allso a testcase for XPointers, which I'll use for inspiration. I'll use one of my oven posts in the examples.

The testcase document is not a normal XHTML document, it start's with:

<!DOCTYPE doc [
<!ATTLIST mylink1 xlink:type CDATA "simple">
<doc xmlns:xlink=""
  <html:style type="text/css">

It's also been a long time since I used DTD, so I had to look at the XML spec.

<!ATTLIST mylink1 xlink:type CDATA "simple">

Means that the mylink1 element can have an attribute named xlink:type (DTD's are not namespace aware so they are defined with prefix (QNAME)). This attribute is of CDATA (StringType) is also states in section 3.3.2 Attribute Defaults that the default value is simple:

In an attribute declaration, #REQUIRED means that the attribute MUST always be provided, #IMPLIED that no default value is provided. [Definition: If the declaration is neither #REQUIRED nor #IMPLIED, then the AttValue value contains the declared default value; the #FIXED keyword states that the attribute MUST always have the default value. When an XML processor encounters an element without a specification for an attribute for which it has read a default value declaration, it MUST report the attribute with the declared default value to the application.]

so if the element does not have an attribute the XML processor is to report it like it had one like xlink:type="simple". The other two attribute declarations says that the <p> and <dic> elements can have an attribute named id of the ID type. The #IMPLIED means that it's optional, and I have never realized why it's called implied (da: underforstået; stiltiende; implicit; (også) antydet; (jur.) indirekte.). These are defined as ID's since it's demanded by the XPointer spec where the definition of a DTD-determined ID (in section 3.2 Shorthand Pointer states:

[Definition: An attribute information item is a DTD-determined ID if and only if it has a [type definition] property whose value is equal to ID.]

and it's needed as stated in a note i en the end of that section:

A shorthand pointer provides, for resources with XML-based media types, a rough analog of HTML fragment identifier behavior. However, if ID typing information is not available because no DTD, schema, or application-specific information is available, the pointer will not identify any element. There are several ways to make element identification more reliable. For example, the creator of a resource can use an internal DTD subset to indicate the presence of ID-typed attributes, and the creator of a pointer can, instead of a shorthand pointer, use a scheme-based pointer or provide one or more schemes that address the desired element in other ways.

The post I'll be using as an example is Web traffic for the WSRP4J demo which should be a valid XHTML 1.0, but it isn't according to the W3C Validator service. The documents start like:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns=''

It states that it is a XHTML document following it strict in accordance with the XHTML 1.0 Strict DTD, but that's just not true (unfortunately).

The annotated DTD does show that the id attribute is defined and as of the ID type.

<!-- core attributes common to most elements
  id       document-wide unique id
  class    space separated list of classes
  style    associated style info
  title    advisory title/amplification
<!ENTITY % coreattrs
 "id          ID             #IMPLIED
  class       CDATA          #IMPLIED
  style       %StyleSheet;   #IMPLIED
  title       %Text;         #IMPLIED"