This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 21945 - Does responseXML ever return an XMLDocument
Summary: Does responseXML ever return an XMLDocument
Status: RESOLVED DUPLICATE of bug 25028
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: XHR (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-06 21:59 UTC by Erik Arvidsson
Modified: 2014-05-20 14:41 UTC (History)
10 users (show)

See Also:


Attachments

Description Erik Arvidsson 2013-05-06 21:59:35 UTC
The IDL says Document? but I'm curious if one could check the type of the returned document to determing if it is an HTML Document or an XMLDocument?

For example, it might be useful to know if xhr.responseXML.createElement('div') would create an HTMLDivElement or an Element object.
Comment 1 Elliott Sprehn 2013-05-06 22:33:01 UTC
I think the text in the spec for XMLDocument might explain this:

http://dom.spec.whatwg.org/#xmldocument

"""A document is assumed to be an XML document unless it is flagged as being an HTML document. Whether a document is an HTML document or an XML document affects the behavior of certain APIs."""

So createDocument() returns an XMLDocument if you pass no arguments and an HTMLDocument if you pass the HTML namespace.

So you know createElement will return an HTMLDivElement if responseXML instanceof XMLDocument is false.
Comment 2 Elliott Sprehn 2013-05-06 22:42:33 UTC
Also note that real world implementations absolutely do return an HTMLDocument or a plain Document (now XMLDocument) based on the content type from responseXML. Gecko, Webkit and Blink all will pick one or the other.
Comment 3 Anne 2013-05-06 23:02:44 UTC
The "XML document" and "HTML document" flag thingie is distinct from the interface going around.

As for what document.createElement() does. I recommend reading bug 19431.
Comment 4 Elliott Sprehn 2013-05-06 23:17:12 UTC
(In reply to comment #3)
> The "XML document" and "HTML document" flag thingie is distinct from the
> interface going around.

Right, so responseXML can be an XMLDocument or an HTMLDocument but createElement will produces HTMLElement instances.

> 
> As for what document.createElement() does. I recommend reading bug 19431.

That thread isn't clear to me. How do I know if a random document created by document.implementation.createDocument() will produce an HTMLElement or an Element when I do createElement('div') ?
Comment 5 Anne 2013-05-06 23:23:06 UTC
FWIW, createDocument() always creates a document marked as "XML document".

That bug is about what document.createElement() should do and whether it should depend on the type of document at all. Currently it only has a few exceptions for "HTML document" flagged document objects, but only with regards to casing.
Comment 6 Simon Pieters 2013-05-07 09:36:40 UTC
(In reply to comment #4)
> Right, so responseXML can be an XMLDocument or an HTMLDocument but
> createElement will produces HTMLElement instances.

No. responseXML can only be Document. HTMLDocument no longer exists (it has been merged with Document). XMLDocument is only returned by the document.createDocument() API. As Anne said, "HTML document" and "XML document" are different concepts.

> That thread isn't clear to me. How do I know if a random document created by
> document.implementation.createDocument() will produce an HTMLElement or an
> Element when I do createElement('div') ?

Currently createElement('div') always produces an HTMLDivElement, regardless of the document.
Comment 7 Olli Pettay 2013-05-07 09:58:41 UTC
(In reply to comment #6)
> Currently createElement('div') always produces an HTMLDivElement, regardless
> of the document.
Per spec, but not per implementations. Not sure which one is wrong.
I think spec, but not sure...
Comment 8 Boris Zbarsky 2013-05-07 13:58:43 UTC
> HTMLDocument no longer exists (it has been merged with Document)

Which no one implements in practice and which is not clearly desirable anyway, right?
Comment 9 Erik Arvidsson 2013-05-07 15:25:27 UTC
(In reply to comment #8)
> > HTMLDocument no longer exists (it has been merged with Document)
> 
> Which no one implements in practice and which is not clearly desirable
> anyway, right?

FWIW, IE9+ only implements Document. It does not have an XMLDocument nor HTMLDocument.
Comment 10 Boris Zbarsky 2013-05-07 16:30:40 UTC
In IE9 the thing returned from responseXML isn't even instanceof Document and is otherwise all sorts of weird (toString on it throws, Object.prototype.toString.call returns "[object Object]", etc, etc).  It certainly doesn't support various Document stuff from the spec like the named getter and write().

So I guess you could argue that IE has merged Document and HTMLDocument by making only HTML documents be Document.... I'm not sure that's useful.
Comment 11 Erik Arvidsson 2013-05-07 19:41:18 UTC
(In reply to comment #10)
> In IE9 the thing returned from responseXML isn't even instanceof Document
> and is otherwise all sorts of weird (toString on it throws,
> Object.prototype.toString.call returns "[object Object]", etc, etc).  It
> certainly doesn't support various Document stuff from the spec like the
> named getter and write().
> 
> So I guess you could argue that IE has merged Document and HTMLDocument by
> making only HTML documents be Document.... I'm not sure that's useful.

That was in IE9... In IE10 the following asserts all passes.

var xhr = new XMLHttpRequest;
xhr.open('GET', 'test.xml', false);
xhr.send();

assert(Object.prototype.toString.call(xhr.responseXML) === '[object Document]');
assert(xhr.responseXML instanceof Document);
Comment 12 Boris Zbarsky 2013-05-08 02:11:22 UTC
Ah, interesting.  Does IE10 support the named getter on such documents?  What does it do with document.write() on them?
Comment 13 Erik Arvidsson 2013-05-08 15:14:05 UTC
(In reply to comment #12)
> Ah, interesting.  Does IE10 support the named getter on such documents? 
> What does it do with document.write() on them?

Based on my testing... The MS guys are now subscribed to this bug so they can probably answer these questions better.

* document.write throws (maybe it works during loading of the doc... I didn't test)

* Named getters works
Comment 14 Anne 2014-05-20 14:41:16 UTC

*** This bug has been marked as a duplicate of bug 25028 ***