0.2.0 • Published 9 years ago

sane-domparser-error v0.2.0

Weekly downloads
3,940
License
BSD-2-Clause
Repository
github
Last release
9 years ago

sane-domparser-error

Provides sane and machine readable parser errors for DOMParser and XHR (with XMLHttpRequest.responseType = 'document').

Why?

DOMParser and XHR currently do not throw an exception if a document could not be parsed, but instead return an error document.

Instead of

<parsererror xmlns="http://www.mozilla.org/newlayout/xml/parsererror.xml">
  XML Parsing Error: prefix not bound to a namespace\n Location: file:////tmp/index.html
  Line Number 1, Column 57:
  <sourcetext>
    &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;&lt;head/&gt;&lt;body&gt;&lt;namespace:customtag&gt;&lt;!-- namespace:customtag--&gt;&lt;/namespace:customtag&gt;&lt;/body&gt;&lt;/html&gt;
    --------------------------------------------------------^
  </sourcetext>
</parsererror>

you'll receive

new Error('XML Parsing Error: prefix not bound to a namespace');

Develop

$ npm run-script watchify
$ xdg-open test/test.html

or just

$ npm test