npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

libxml-xsd

v0.5.2

Published

XSD validator based on libxml

Downloads

1,555

Readme

node-libxml-xsd

Build status Code Climate NPM version

XSD validation for node.js using libxml

Installation

npm install libxml-xsd

Basic usage

var xsd = require('libxml-xsd');

xsd.parseFile(schemaPath, function(err, schema){
  schema.validate(documentString, function(err, validationErrors){
    // err contains any technical error
    // validationError is an array, null if the validation is ok
  });  
});

Libxmljs integration

Node-libxml-xsd depends on libxmljs that bundles libxml.

The libxmljs module required by node-libxml-xsd is exposed as require('libxml-xsd').libxmljs. This prevents depending on libxmljs twice which is not optimal and source of weird bugs.

It is possible to work with libxmljs 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.

Sync or async

The same parse() and validate() functions can be used in synchronous mode simply by removing the callback parameter. In this case if a technical error occurs it will be thrown and validation errors will be returned.

var xsd = require('libxml-xsd');

var schema = xsd.parse(schemaString);

var validationErrors = schema.validate(documentString);

The asynchronous functions use the libuv work queue to provide parallelized computation in node.js worker threads. This makes it non-blocking for the main event loop of node.js.

Note that libxmljs parsing doesn't use the work queue, so only a part of the process is actually parallelized.

The tasks being mostly CPU bound and very fast it is not a big problem to use synchronous mode. But remember that if you use some includes the parsing task becomes IO bound.

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, 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. There is no system dependancy otherwise as libxml is bundled by libxmljs.

API Reference

Node.js bindings for XSD validation from libxml

Members

##libxml-xsd.parse(source, [callback]) Parse a XSD schema

If no callback is given the function will run synchronously and return the result or throw an error.

Params

  • source string | Document - The content of the schema as a string or a libxmljs document
  • [callback] parseCallback - The callback that handles the response. Expects err and Schema object.

Returns: Schema - Only if no callback is given.
##libxml-xsd.parseFile(sourcePath, callback) Parse a XSD schema

Params

  • sourcePath stringPath - The path of the file
  • callback parseFileCallback - The callback that handles the response. Expects err and Schema object.

##class: libxml-xsd~Schema Members

###new libxml-xsd~Schema(schemaDoc, schemaObj) A compiled schema. Do not call this constructor, instead use parse or parseFile.

store both the source document and the parsed schema if we don't store the schema doc it will be deleted by garbage collector and it will result in segfaults.

Params

  • schemaDoc Document - XML document source of the schema
  • schemaObj Document - Simple wrapper of a XSD schema

Scope: inner class of libxml-xsd
###schema.validate(source, [callback]) Validate a XML document over a schema

If no callback is given the function will run synchronously and return the result or throw an error.

Params

  • source string | Document - The XML content to validate with the schema, to be given as a string or a libxmljs document
  • [callback] validateCallback - The callback that handles the response. Expects err and an array of validation errors, null if none.

Returns: string | Document - Only if no callback is given. An array of validation errors, null if none.
###schema.validateFile(sourcePath, callback) Apply a schema to a XML file

Params

  • sourcePath string - The path of the file to read
  • callback validateFileCallback - The callback that handles the response. Expects err and an array of validation errors null if none.

documented by jsdoc-to-markdown.