1.0.16 • Published 3 years ago

@xml-tools/validation v1.0.16

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

npm (scoped)

@xml-tools/validation

APIs which assist in implementing Validations / Diagnostics logic for XML.

Installation

With npm:

  • npm install @xml-tools/validation

With Yarn

  • yarn add @xml-tools/validation

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 { validate } = require("xml-tools/validation");

const xmlText = `<note>
                     <to>Bill</to>
                 </note>
`;

const { cst, tokenVector } = parse(xmlText);
const xmlDocAst = buildAst(cst, tokenVector);
const issues = validate({
  doc: xmlDocAst,
  validators: {
    element: [
      (node) => {
        if (node.name === "note") {
          const hasFrom = node.subElements.find(
            (subNode) => subNode.name === "from"
          );
          if (hasFrom === undefined) {
            return [
              {
                msg: "A Note Element **must** have a `from` subElement",
                node: node,
              },
            ];
          }
        }
        return [];
      },
    ],
  },
});

console.log(issues[0].msg); // -> "A Note Element **must** have a `from` subElement"
// Issue position can be extracted from the relevant ASTNode.
console.log(issues[0].node.position.endLine); // -> 3

Support

Please open issues on github.

Contributing

See CONTRIBUTING.md.

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago