sane-domparser-error

WebJar for sane-domparser-error

License

License

BSD 2-Clause
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

sane-domparser-error
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

sane-domparser-error
WebJar for sane-domparser-error
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/cburgmer/sane-domparser-error

Download sane-domparser-error

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/sane-domparser-error/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>sane-domparser-error</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/sane-domparser-error/
implementation 'org.webjars.npm:sane-domparser-error:0.2.0'
// https://jarcasting.com/artifacts/org.webjars.npm/sane-domparser-error/
implementation ("org.webjars.npm:sane-domparser-error:0.2.0")
'org.webjars.npm:sane-domparser-error:jar:0.2.0'
<dependency org="org.webjars.npm" name="sane-domparser-error" rev="0.2.0">
  <artifact name="sane-domparser-error" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='sane-domparser-error', version='0.2.0')
)
libraryDependencies += "org.webjars.npm" % "sane-domparser-error" % "0.2.0"
[org.webjars.npm/sane-domparser-error "0.2.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

sane-domparser-error

NPM version

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');

Usage

var saneError = require('sane-domparser-error');

var xhr = new XMLHttpRequest();
xhr.onload = function() {
  saneError.failOnParseError(xhr.responseXML);
  // ... the happy path from here ...
}
xhr.open("GET", "file.html");
xhr.responseType = "document";
xhr.send();

and

var saneError = require('sane-domparser-error');

var p = new DOMParser(),
    doc = p.parseFromString(xhtml, "application/xml");

saneError.failOnParseError(doc);
// ... the happy path from here ...

Develop

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

or just

$ npm test

Versions

Version
0.2.0