https://github.com/nikku/node-xsd-schema-validator
A schema (XSD) validator for NodeJS
https://github.com/nikku/node-xsd-schema-validator
nodejs xsd-validation
Last synced: over 1 year ago
JSON representation
A schema (XSD) validator for NodeJS
- Host: GitHub
- URL: https://github.com/nikku/node-xsd-schema-validator
- Owner: nikku
- License: mit
- Created: 2014-03-07T22:09:34.000Z (over 12 years ago)
- Default Branch: main
- Last Pushed: 2025-01-23T20:15:38.000Z (over 1 year ago)
- Last Synced: 2025-04-12T23:39:14.790Z (over 1 year ago)
- Topics: nodejs, xsd-validation
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/xsd-schema-validator
- Size: 229 KB
- Stars: 54
- Watchers: 6
- Forks: 23
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Support: support/XMLValidator.java
Awesome Lists containing this project
README
# xsd-schema-validator
[](https://github.com/nikku/node-xsd-schema-validator/actions/workflows/CI.yml)
A (XSD) schema validator for [NodeJS](nodejs.org) that uses [Java](https://www.java.com) to perform the actual validation. [:arrow_right: Why?](#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](http://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/) you need to define `JAVA_HOME` manually.
## Installation
Install the package via [npm](http://npmjs.org):
```
npm install --save xsd-schema-validator
```
## Usage
Use in your application:
```javascript
var validator = require('xsd-schema-validator');
var xmlStr = '';
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:
```javascript
var xmlStream = fs.createReadableStream('some.xml');
const result = await validator.validateXML(xmlStream);
```
You may validate files, too:
```javascript
const result = validator.validateXML({ file: 'some.xml' }, ...);
```
## Why
Because Java can do schema validation and NodeJS cannot.
## License
MIT