# xsd-schema-validator

> A (XSD) schema validator for nodejs

Latest version **0.11.0** (published 2025-01-23) · MIT license · 36.4K weekly downloads

## Install

```sh
npm install xsd-schema-validator
pnpm add xsd-schema-validator
yarn add xsd-schema-validator
bun add xsd-schema-validator
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: no esm support; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.11.0 |
| Published | 2025-01-23 |
| First published | 2014-03-07 |
| Weekly downloads | 36.4K |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 18 |
| Dependencies | 1 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 60 |
| Author | Nico Rehwaldt |
| Maintainers | nikku |
| Keywords | xsd, xml, schema, validator, validation |

## Links

- npm: https://www.npmjs.com/package/xsd-schema-validator
- Repository: https://github.com/nikku/node-xsd-schema-validator
- Homepage: https://github.com/nikku/node-xsd-schema-validator#readme
- Issues: https://github.com/nikku/node-xsd-schema-validator/issues
- npm.io page: https://npm.io/package/xsd-schema-validator

## Dependencies (1)

- [which](https://npm.io/package/which.md) ^5.0.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.11.0 (latest) — 2025-01-23
- 0.10.0 — 2024-11-18
- 0.9.0 — 2024-02-18
- 0.8.1 — 2024-01-16
- 0.8.0 — 2024-01-12
- 0.7.0 — 2021-04-22
- 0.6.0 — 2018-02-02
- 0.5.0 — 2016-11-24
- 0.4.0 — 2016-11-24
- 0.3.1 — 2015-06-05
- 0.3.0 — 2015-02-02
- 0.2.0 — 2014-12-31
- 0.1.0 — 2014-09-22
- 0.0.4 — 2014-08-19
- 0.0.3 — 2014-03-07
- … 1 more at https://npm.io/package/xsd-schema-validator/versions

## README

# xsd-schema-validator

[![CI](https://github.com/nikku/node-xsd-schema-validator/actions/workflows/CI.yml/badge.svg)](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 = '<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:

```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

---
_Source: https://npm.io/package/xsd-schema-validator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
