Skip to content

nikku/node-xsd-schema-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jan 16, 2024
fbf6f01 · Jan 16, 2024

History

78 Commits
Jan 12, 2024
Jan 12, 2024
Nov 24, 2016
Jan 12, 2024
Jan 12, 2024
Sep 22, 2014
Jan 16, 2024
Mar 7, 2014
Jan 12, 2024
Jan 16, 2024
Jan 16, 2024
Jan 14, 2024

Repository files navigation

xsd-schema-validator

CI

A (XSD) schema validator for NodeJS that uses Java to perform the actual validation. ➡️ 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 />';

try {
  const result = await validator.validateXML(xmlStr, 'resources/foo.xsd');

  result.valid; // true
} catch (err) {
  console.error('validation error', err);
}

You may validate readable streams:

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

const result = await validator.validateXML(xmlStream);

You may validate files, too:

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

Why

Because Java can do schema validation and NodeJS cannot.

License

MIT