1.1.1 • Published 3 years ago

@xml-tools/constraints v1.1.1

Weekly downloads
111
License
Apache-2.0
Repository
github
Last release
3 years ago

npm (scoped)

@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.