W3C home > Mailing lists > Public > public-html@w3.org > June 2008

Re: innerHTML in XML

From: Ian Hickson <ian@hixie.ch>
Date: Sun, 1 Jun 2008 21:53:42 +0000 (UTC)
To: Julian Reschke <julian.reschke@gmx.de>, Cameron McCormack <cam@mcc.id.au>
Cc: public-html@w3.org
Message-ID: <Pine.LNX.4.62.0806012141520.504@hixie.dreamhostps.com>
On Sun, 1 Jun 2008, Julian Reschke wrote:
> Ian Hickson wrote:
> > On Sun, 1 Jun 2008, 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?
> > 
> > If we didn't do this, round-tripping would break. For example this:
> > 
> >     <foo xmlns="a:"><bar xmlns=""/></foo>
> > 
> >     foo.innerHTML = foo.innerHTML;
> > 
> > ...would turn the DOM into the equivalent of:
> > 
> >     <a:foo xmlns:a="a:"><a:bar/></a:foo>
> 
> I guess the question was whether this is a requirement that exceeds 
> normal XML serializations requirements.

Yes, it is.


> For the example, yes, obviously the xmlns="" is required.

Why? <bar/> would be just as good a serialisation as <bar xmlns=""/> for 
the contents of the <foo> element, since the <foo> element's own namespace 
declarations aren't accessible.


> The question is, is it required to add the xmlns="" in cases like
> 
> 	<foo xmlns=""><bar xmlns=""/></foo>
> 
> ?

For the innerHTML of what? <foo>? That's the same case as far as I can 
tell, since the namespace of <foo> doesn't have any effect on the 
serialisation of its contents.


> It wouldn't be needed for the sake of a correct XML serialization, but 
> it would be *useful* to make copy & parse robust.

Right. The idea is to make the output of innerHTML, when it's XML, not be 
reliant on the context into which it is serialised. XML has this problem 
with entities, and it causes all kinds of problems.


On Sun, 1 Jun 2008, Julian Reschke wrote:
> > >
> > > I guess the question was whether this is a requirement that exceeds 
> > > normal XML serializations requirements.
> > > 
> > > For the example, yes, obviously the xmlns="" is required.
> > > 
> > > The question is, is it required to add the xmlns="" in cases like
> > > 
> > > 	<foo xmlns=""><bar xmlns=""/></foo>
> > > 
> > > ?
> > 
> > From the wording above it doesn’t sound like the one on the <bar> is 
> > required.
> 
> Right. But is the one in <foo> required? I think so (per HTML5, although 
> not per XML).

I don't understand what you are asking. <foo> doesn't get included in its 
innerHTML serialisation of <foo>. The one on the <bar> element is 
required, since otherwise the element has no default namespace in scope.

If you were to serialise the whole document, then the one on <foo> would 
be required, but not the one on <bar>, to satisfy the requirement "the 
default namespace in scope for those elements must be explicitly declared 
as the empty string".

HTH,
-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Sunday, 1 June 2008 21:54:30 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 9 May 2012 00:16:18 GMT