XMLHttpRequest.responseXML and invalid XML documents

I've been asked to re-post some things I sent to the WHATWG list regarding  
XMLHttpRequest..

Originally posted to
http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-June/004119.html

Spec says about responseXML :

> If the document was not an XML document, or if the document could
> not be parsed (due to an XML well-formedness error or unsupported
> character encoding, for instance), returns null.

All major browsers return an empty document instead under most of
these conditions.

Exceptions:

- FireFox *does* return null if the document is sent as text/html
- FireFox and Opera guess UTF-8 encoding if the encoding sent from
the server is unknown, and parses document.

Requiring that browsers return null may not be compatible with
existing content. Scripts that today use for example
request.responseXML.getElementsByTagName()
would fail with an error if responseXML was null, and today there is
virtually no point of saying "if(x.responseXML)" first since it will
nearly always be a document object so no scripts will be written that
way. Could we standardise returning an empty document instead, for
all these conditions?

-- 
Hallvord R. M. Steen
Core QA JavaScript tester, Opera Software
http://www.opera.com/
Opera - simply the best Internet experience

Received on Monday, 24 April 2006 02:34:09 UTC