W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2012

DOMParser Errors Should Be Exceptions

From: Yehuda Katz <wycats@gmail.com>
Date: Wed, 23 May 2012 12:03:19 -0700
Message-ID: <CAMFeDTXn3GSwzaoWAQyjtmrbiY645oQPSyetB3X=_gycpm1taw@mail.gmail.com>
To: public-webapps WG <public-webapps@w3.org>
In the current DOM parsing spec[1], errors in XML (or SVG) are handled as

> Let root be a new Element, with its local name set to "parsererror" and
> namespace set to "http://www.mozilla.org/newlayout/xml/parsererror.xml".
> At this point user agents may append nodes to root, for example to
> the nature of the error.

In practice, browsers implement error handling in this way. The output for
the following code is given below.

(new XMLSerializer).serializeToString((new
DOMParser).parseFromString("<tr>hi", "text/xml"));

As a result, jQuery looks for a parserror tag and re-raises an error when
parsing XML[2].

In my view, the DOMParser should throw an exception, and not insert a
partially unspecified parserror tag.


=== Output


"<tr><parsererror xmlns="http://www.w3.org/1999/xhtml" style="display:
block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em;
margin: 1em; background-color: #fdd; color: black"><h3>This page contains
the following errors:</h3><div
style="font-family:monospace;font-size:12px">error on line 1 at column 7:
Extra content at the end of the document
</div><h3>Below is a rendering of the page up to the first


"<?xml-stylesheet href=\"chrome://global/locale/intl.css\"
type=\"text/css\"?>\n<parsererror xmlns=\"
http://www.mozilla.org/newlayout/xml/parsererror.xml\">XML Parsing Error:
no element found\nLocation:
https://getfirebug.com/firstrun#Firebug%201.9.2\nLine Number 1, Column


"<?xml version="1.0"?><parsererror xmlns="

[1] http://html5.org/specs/dom-parsing.html
[2] https://github.com/jquery/jquery/blob/master/src/core.js#L526-528

Yehuda Katz
(ph) 718.877.1325
Received on Wednesday, 23 May 2012 19:04:10 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:34 UTC