-
Notifications
You must be signed in to change notification settings - Fork 12
/
readme.hbs
60 lines (39 loc) · 2.6 KB
/
readme.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
libxmljs2-xsd
===============
[![NPM version](https://badge.fury.io/js/libxmljs2-xsd.svg)](http://badge.fury.io/js/libxmljs2-xsd)
*XSD 1.0 validation for node.js 14.x and 16.x using [libxml](http://xmlsoft.org/) via [libxmljs2](https://github.com/marudor/libxmljs2)*
As of now, XSD 1.1 is not supported, and the author does not actively work on it. Feel free to submit a PR if you want to.
Installation
------------
npm install libxmljs2-xsd
On windows there are several prerequisites that need to be met before an install will work.
[Windows-Build-Tools](https://github.com/felixrieseberg/windows-build-tools) is a great helper module for this task.
npm install --global --production windows-build-tools
npm install libxmljs2-xsd
Basic usage
-----------
```js
var xsd = require('libxmljs2-xsd');
// throws in case of error
var schema = xsd.parseFile(schemaPath);
// throws in case of technical error, returns a list of validation errors,
// or null if the document is valid
var validationErrors = schema.validate(documentString);
```
libxmljs2 integration
--------------------
libxmljs2-xsd depends on [libxmljs2](https://github.com/marudor/libxmljs2) that bundles libxml.
The libxmljs2 module required by node-libxml-xsd is exposed as ```require('libxmljs2-xsd').libxmljs```. This prevents depending on libxmljs2 twice which is not optimal and source of weird bugs.
It is possible to work with libxmljs2 documents instead of strings as inputs to the *parse()* and *validate()* functions.
Imports and includes
--------------------
XSD includes are supported but relative paths must be given from the execution directory, usually the root of the project.
Includes are resolved when parsing the schema. Therefore the parsing task becomes IO bound, which is why you should not use synchronous parsing when you expect some includes.
Environment compatibility
-------------------------
For now 64bits linux and 32bits windows are confirmed. Other environments are probably ok, but not checked. Please report an issue if you encounter some difficulties.
node-libxml-xsd depends on [node-gyp](https://github.com/TooTallNate/node-gyp), you will need to meet its requirements. This can be a bit painful mostly for windows users. The node-gyp version bundled in your npm will have to be greater than 0.13.0, so you might have to follow [these instructions to upgrade](https://github.com/TooTallNate/node-gyp/wiki/Updating-npm's-bundled-node-gyp). There is no system dependancy otherwise as libxml is bundled by libxmljs2.
API Reference
=============
{{>main}}
*documented by [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown)*.