@xml-tools/constraints
v1.1.1
Published
XML constraints validations
Downloads
12,039
Readme
@xml-tools/constraints
Validations for XML constraints.
The following constraints are currently implemented:
- Uniqueness of attribute keys inside the same element.
- Element opening tag name must be identical to the element closing tag name.
Installation
With npm:
npm install @xml-tools/constraints
With Yarn
yarn add @xml-tools/constraints
Usage
Please see the TypeScript Definitions for full API details.
A simple usage example:
const { parse } = require("@xml-tools/parser");
const { buildAst } = require("@xml-tools/ast");
const { checkConstraints } = require("@xml-tools/constraints");
const xmlText = `
<note>
<to>Bill</to>
<from>Tim</from>
</note-typo>`;
const { cst, tokenVector } = parse(xmlText);
const document = buildAst(cst, tokenVector);
const validationIssues = checkConstraints(document);
console.log(validationIssues[0].msg); // --> 'opening tag: "note" must match closing tag: "note-typo"
Support
Please open issues on github.
Contributing
See CONTRIBUTING.md.