Re: How can I create a HTMLDocument from the DOMImplementation

On Wed, Aug 19, 2009 at 3:57 PM, Jonas Sicking<jonas@sicking.cc> wrote:
> On Wed, Aug 19, 2009 at 12:33 PM, Ian Hickson<ian@hixie.ch> wrote:
>> On Wed, 19 Aug 2009, Jonas Sicking wrote:
>>> On Wed, Aug 19, 2009 at 12:18 PM, Ian Hickson<ian@hixie.ch> wrote:
>>> > On Wed, 19 Aug 2009, Jonas Sicking wrote:
>>> >> On Tue, Aug 18, 2009 at 11:33 PM, Ian Hickson<ian@hixie.ch> wrote:
>>> >> > On Tue, 18 Aug 2009, Bo Yang wrote:
>>> >> >>
>>> >> >> The Core module define the DOMImplementation interface which is used to
>>> >> >> bootstrap the DOM, to create Document and DocumentType. But I can't find
>>> >> >> a way to create a specific type of Document from that interface. I mean,
>>> >> >> how can I create HTMLDocument from some DOMImplementation? Thanks!
>>> >> >
>>> >> > With HTML5, all Document objects implement all the subinterfaces
>>> >> > (HTMLDocument, SVGDocument, etc) all the time, so going forward it'll be a
>>> >> > moot point (unless that requirement is changed).
>>> >>
>>> >> But how do you create a text/html document (where HTML elements
>>> >> .nodeName is uppercase), vs. a application/xhtml+xml document (where
>>> >> HTML elements .nodeName is lowercase)?
>>> >
>>> > On Wed, 19 Aug 2009, Anne van Kesteren wrote:
>>> >>
>>> >> By using document.open() iirc.
>>> >
>>> > Yeah, that's one way. Immediately call .open() on the Document after
>>> > creating it.
>>>
>>> Wow, that's a really unintuitive design. Why was this design chosen?
>>
>> It wasn't really chosen. I think we just ended up there while trying to
>> address other issues.
>
> What other issues?
>
> I.e. what would be lost by making the choise between a "text/html
> document" vs "non-text/html document" be chosen at construction time?
>
> One thing that seems unfortunate with the current API is that you can
> call .open() on a document dynamically, thus changing behavior of any
> node which has that node as ownerDocument (note that while nodes are
> removed from the document when .open() is called, they don't change
> ownerDocument).

In addition to being unintuitive, it's sort of terrible JavaScript API
design besides. It'd be more idiomatic for the Document constructor to
take a bag of arguments. E.g.:

   var d = new Document({ mimetype: "text/html", ... });

Regards

Received on Wednesday, 19 August 2009 23:34:08 UTC