Skip to content

Validation of XML against XSD schema, written in pure Javascript, browser or node.js friendly.

Notifications You must be signed in to change notification settings

paulwardrip/xmlschema.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xmlschema.js

Implementation of XML schema validation in pure Javascript.

Most XSD functionality is implemented here, except for the following: xs:key, xs:redefine, xs:union

Installing

npm install xmlschema.js

or You can install using bower:

bower install xmlschema.js

or yarn

yarn add xmlschema.js

Usage

xmlschema([xsd]).validate(xml[, callback]);

Where xsd/xml are a URL, XMLDocument or xml string. If xsd is not provided the schema will be loaded from the xsi:schemaLocation in the xml document. The validate method returns a promise (implementation depends on environment and available libraries, it provides: then(), catch()).

You will need to register a callback with the validate method or the promise it returns: function callback(result)

The result object contains the following:

  • valid: boolean, did the xml validate
  • message: a status message, example: "Validated 14 elements and 8 attributes, document is invalid."
  • errors: an array of error messages.
  • warnings: an array of warnings.
  • xsd: an object representing the xsd document
    • doc: as an XMLDocument object.
    • str: as a string.
  • xml: an object representing the xml document
    • doc: as an XMLDocument object.
    • str: as a string.

About

Validation of XML against XSD schema, written in pure Javascript, browser or node.js friendly.

Resources

Stars

Watchers

Forks

Packages

No packages published