@xml-tools/constraints
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i @xml-tools/constraints

Weekly Downloads

1,310

Version

1.1.1

License

Apache-2.0

Unpacked Size

26.4 kB

Total Files

9

Last publish

Collaborators

  • rima.sirich
  • oss_rima_bot
  • shahars