{"library":"node-schematron","title":"node-schematron","description":"The `node-schematron` package provides a pure JavaScript implementation of the Schematron validation language, designed for use in Node.js environments, web browsers (with bundlers like Webpack), and as a command-line interface (CLI) tool. As of version 2.1.0, it offers a robust solution for validating XML documents against Schematron schemas, returning results as a JSON object. Key differentiators include its complete JavaScript implementation, avoiding native dependencies, and support for Schematron includes and various CLI options for file globbing and output reporters. The library utilizes `fontoxpath` for XPath 3.1 queries, though it notes that `fontoxpath` is not yet feature-complete. While there's no explicit release cadence, the project appears actively maintained, offering a flexible and integrated Schematron solution for JavaScript ecosystems.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install node-schematron"],"cli":{"name":"schematron","version":null}},"imports":["import { Schema } from 'node-schematron';","import { registerCustomXPathFunction } from 'node-schematron';","schema.validateString('<xml/>', options);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Schema } from 'node-schematron';\n\nconst schematronSchema = `\n<schema xmlns=\"http://purl.oclc.org/dsdl/schematron\">\n\t<pattern>\n\t\t<rule context=\"thunder\">\n\t\t\t<let name=\"lightning\" select=\"@foo\"/>\n\t\t\t<report test=\"$lightning = 'bar'\">\n\t\t\t\tSkeet boop <value-of select=\"$lightning\" />\n\t\t\t</report>\n\t\t\t<assert test=\"@type = 'storm'\">\n\t\t\t\tThunder must have a 'type' attribute with value 'storm'.\n\t\t\t</report>\n\t\t</rule>\n\t\t<rule context=\"xml\">\n\t\t\t<assert test=\"count(thunder) > 0\">\n\t\t\t\tXML document must contain at least one thunder element.\n\t\t\t</assert>\n\t\t</rule>\n\t</pattern>\n</schema>`;\n\nconst schema = Schema.fromString(schematronSchema);\n\nconst xmlToValidate = `\n<xml foo=\"err\">\n\t<thunder foo=\"bar\" type=\"storm\" />\n</xml>`;\n\nconst results = schema.validateString(xmlToValidate, { debug: true });\n\nconsole.log(JSON.stringify(results, null, 2));\n/* Expected Output for the report (assertion passes):\n[\n  {\n    \"isReport\": true,\n    \"context\": \"<thunder foo=\"bar\" type=\"storm\"/>\",\n    \"message\": \"\\n\\t\\t\\t\\tSkeet boop bar\\n\\t\\t\\t\"\n  }\n]\n*/","lang":"typescript","description":"This quickstart demonstrates how to initialize a Schematron `Schema` from a string and validate an XML string, logging the results.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}