[whatwg] Question about DOMImplementation.createHTMLDocument() specifications

Thomas Fétiveau tfetiveau at tokom.fr
Thu May 9 22:10:38 PDT 2013


Hi,

There is something unclear to me in the current HTML spec:

- The "initial" insertion mode of the tree construction stage specifies 
to add a doctype to the associated document when a doctype token shows 
up: 
http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html#the-initial-insertion-mode

- However the document object has already been built at this stage and 
is an HTML document, thus created by DOMImplementation.createHTMLDocument().

   But the specification of this methods says :

> The |createHTMLDocument(title)| method must run these steps:
>
> 1.
>
>     Let doc be a new document
>     <http://dom.spec.whatwg.org/#concept-document> that is an HTML
>     document <http://dom.spec.whatwg.org/#html-document>.
>
> 2.
>
>     Set doc's content type
>     <http://dom.spec.whatwg.org/#concept-document-content-type> to
>     "|text/html|".
>
> 3.
>
>     Create a doctype <http://dom.spec.whatwg.org/#concept-doctype>,
>     with "|html|" as its name
>     <http://dom.spec.whatwg.org/#concept-doctype-name> and with its
>     node document <http://dom.spec.whatwg.org/#concept-node-document>
>     set to doc. Append
>     <http://dom.spec.whatwg.org/#concept-node-append> the newly
>     created node to doc.
>
> 4.
>
>     Create an |html| element in the HTML namespace
>     <http://dom.spec.whatwg.org/#html-namespace>, and append
>     <http://dom.spec.whatwg.org/#concept-node-append> it to doc.
>
> 5.
>
>     Create a |head| element in the HTML namespace
>     <http://dom.spec.whatwg.org/#html-namespace>, and append
>     <http://dom.spec.whatwg.org/#concept-node-append> it to the |html|
>     element created in the previous step.
>
> 6.
>
>     If the title argument is not omitted:
>
>     1.
>
>         Create a |title| element in the HTML namespace
>         <http://dom.spec.whatwg.org/#html-namespace>, and append
>         <http://dom.spec.whatwg.org/#concept-node-append> it to the
>         |head| element created in the previous step.
>
>     2.
>
>         Create a |Text <http://dom.spec.whatwg.org/#text>| node
>         <http://dom.spec.whatwg.org/#concept-node>, set its data
>         <http://dom.spec.whatwg.org/#concept-cd-data> to title (which
>         could be the empty string), and append
>         <http://dom.spec.whatwg.org/#concept-node-append> it to the
>         |title| element created in the previous step.
>
> 7.
>
>     Create a |body| element in the HTML namespace
>     <http://dom.spec.whatwg.org/#html-namespace>, and append
>     <http://dom.spec.whatwg.org/#concept-node-append> it to the |html|
>     element created in the earlier step.
>
> 8.
>
>     doc's origin
>     <http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#origin>
>     is an alias
>     <http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#concept-origin-alias>
>     to the origin
>     <http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#origin>
>     of the context object
>     <http://dom.spec.whatwg.org/#context-object>'s associated document
>     <http://dom.spec.whatwg.org/#concept-document>, and doc's
>     effective script origin
>     <http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#effective-script-origin>
>     is an alias
>     <http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#concept-origin-alias>
>     to the effective script origin
>     <http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#effective-script-origin>
>     of the context object
>     <http://dom.spec.whatwg.org/#context-object>'s associated document
>     <http://dom.spec.whatwg.org/#concept-document>. [HTML]
>     <http://dom.spec.whatwg.org/#refsHTML>
>
> 9.
>
>     Return doc.
>

There is a problem here IMO because if we've already created our HTML 
document object before the initial stage of the tree contruction stage, 
it means it already has a doctype, a HTMLHtmlElement, a HTMLHeadElement, ...

How should we manage that in the "initial", "before html", "after HTML", 
... insertion modes when are asked to append/associate doctypes, html 
element, head element (...) to our assiocated document object which 
already has all that ?

My point is : Shouldn't the  DOMImplementation.createHTMLDocument() just 
create a Document object with  content type set to "text/html" and 
nothing else ?

Thanks and regards,

-- 
Thomas Fétiveau
+33 (0) 623 110 922
www.tokom.fr



More information about the whatwg mailing list