Re: innerHTML in XML

Hi Thomas.

Thomas Broyer:
> On Sun, Jun 1, 2008 at 6:54 AM, Cameron McCormack wrote:
> >
> > Currently the spec says:
> >
> >  If any of the elements in the serialization are in the null namespace,
> >  the default namespace in scope for those elements must be explicitly
> >  declared as the empty string.
> >    — http://dev.w3.org/html5/spec/#innerhtml1
> >
> > Is there any reason for this?  Why not allow elements to be in no
> > namespace by virtue of there being no xmlns="" attribute in
> > ancestor-or-self::*?
> 
> You might have misunderstood that sentence (or have I misunderstood yours?)

Sorry, I wasn’t very clear.

> It says that if an element is in no namespace in the DOM, its
> serialization must have xmlns="" (so that you can copy/paste it into a
> document no matter whether there's a default namespace without
> changing its meaning).

Ah OK, I didn’t realise that requirement was there so that you could
have that copy/paste safety.

> (note that the sentence appears in the context of a paragraph dealing
> with the "return value" of innerHTML, so the process of serializing,
> not parsing).
> 
> If the serialization didn't include the xmlns="" explicitly,
> serializing a tree to, e.g.:
>   <foo:a xmlns:foo="http://example.net/foo"><b/></foo:a>
> Then compare pasting that fragment in the following documents:
>   <c xmlns="">[paste here]</c>
> vs.
>   <d xmlns="http://example.net/foo">[paste here]</d>
> Element <b/> wouldn't be the same when re-parsing the compound documents.
> 
> With the explicit xmlns="" in the serialization, this cannot happen:
>   <foo:a xmlns:foo="http://example.net/foo" xmlns=""><b/></foo:a>

Right.

The reason I asked was because I was looking at XHR, which says that
passing a Document to XMLHttpRequest.send() should cause the document to
be serialised using the innerHTML algorithm and then sent, which would
result in needless xmlns="" attributes in some cases.  (Well, it meant
that I had to change my serialisation functions.)

Thanks,

Cameron

-- 
Cameron McCormack ≝ http://mcc.id.au/

Received on Sunday, 1 June 2008 10:55:23 UTC