Re: xmlns in HTML5

Sam Ruby wrote:
> Steven Pemberton wrote:
> > The much-maligned Appendic C guidelines of XHTML1 were only there to
> > give some hints on how to do this.
>
> If it was much maligned, then perhaps we should consider a different
> approach.

I agree.

> > The upshot of this is that xmlns attributes will remain in the  
> DOM. This
> > is good. And it is all we need.
>
> I would actually make that statement stronger.  HTML 5 requires that
> attributes whose names begin with "xmlns:" be placed in the DOM in a
> certain way.

What you say is true for all practical purposes when talking about  
"the DOM" in browsers. It's not necessarily true in practice and per  
spec for all kinds of things called "the DOM".

The public DOM API is required to throw when setting an attribute  
whose namespace is null and whose local name is "xmlns:foo":
> NAMESPACE_ERR: Raised if the qualifiedName is malformed per the  
> Namespaces in XML specification, if the qualifiedName has a prefix  
> and the             namespaceURI is null, if the qualifiedName has a  
> prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace 
> ", if the qualifiedName or its prefix is "xmlns" and the  
> namespaceURI is different from "http://www.w3.org/2000/xmlns/", or  
> if the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither  
> the qualifiedName nor its prefix is "xmlns".

http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-ElSetAttrNS

Therefore, to comply with the HTML 5 parsing spec, the parser needs a  
back door to the DOM. For example, if you set the html5.enable pref to  
true in a recent nightly build of Firefox trunk, you get a parser that  
uses such a back door.

The Validator.nu HTML Parser exposes the Java DOM API outside  
browsers. It builds the tree using the public API, because it uses the  
JDK/JAXP DOM implementation and the JDK/JAXP doesn't specify a back  
door.

To address situations like this, HTML 5 licenses the parser to drop  
those attributes, which is what the Validator.nu HTML Parser does by  
default when used with the JAXP DOM:
> If the XML API doesn't support attributes in no namespace that are  
> named "xmlns", attributes whose names start with "xmlns:", or  
> attributes in the XMLNS namespace, then the tool may drop such  
> attributes.

http://www.whatwg.org/specs/web-apps/current-work/#coercing-an-html-dom-into-an-infoset

For server-side use, it seems unwise to rely on things that need to be  
mangled in order to make off-the-shelf XML tree implementations not  
throw.

-- 
Henri Sivonen
hsivonen@iki.fi
http://hsivonen.iki.fi/

Received on Friday, 17 July 2009 12:15:30 UTC