xsd-schema-validator

A (XSD) schema validator for nodejs

Usage no npm install needed!

<script type="module">
  import xsdSchemaValidator from 'https://cdn.skypack.dev/xsd-schema-validator';
</script>

README

xsd-schema-validator

CI

A (XSD) schema validator for NodeJS that uses Java to perform the actual validation. :arrow_right: Why?

Prerequisites

Under the hood, this utility uses Java to do the actual validation.

It assumes that javac and java are on the path. If a JAVA_HOME environment variable exists it uses that to locate an installed JDK.

On some platforms, i.e. Mac OSX you need to define JAVA_HOME manually.

Installation

Install the package via npm:

npm install --save xsd-schema-validator

Usage

Use in your application:

var validator = require('xsd-schema-validator');

var xmlStr = '<foo:bar />';

validator.validateXML(xmlStr, 'resources/foo.xsd', function(err, result) {
  if (err) {
    throw err;
  }

  result.valid; // true
});

You may validate readable streams:

var xmlStream = fs.createReadableStream('some.xml');

validator.validateXML(xmlStream, ...);

You may validate files, too:

validator.validateXML({ file: 'some.xml' }, ...);

Why

Because Java can do schema validation and NodeJS cannot.

License

MIT