Git Product home page Git Product logo

xml-validator's Introduction

XML Validator

Typed node.js XML validator.

Installation

Using yarn:

yarn add xml-validator

Using npm:

npm i xml-validator

๐Ÿ‘€ Quickstart

import { XmlValidator } from "../src";

const validator = new XmlValidator();

const validation = validator.validate("<root></root>")

console.log(validation.isValid); // true
console.log(validation.error); // ""

Advanced Example

import { XmlValidator } from "../src";

const validator = new XmlValidator({
    userAgent: "MyMozilaFirefox",
});

{
    console.log("example1")
    const { isValid, error } = validator.validate("<root</root>")
    console.log(isValid); // false
    console.log(error); // about:blank:1:6: disallowed character in tag name.
}

{
    console.log("example2")
    const { isValid, error } = validator.validate("<root></root>")
    console.log(isValid); // true
    console.log(error); // ""
}

validator.validateUrl("https://www.w3schools.com/xml/simple.xml")
    .then(validation => {
        console.log("example3")
        console.log(validation.isValid); // true
        console.log(validation.error); // ""
    })

validator.validateUrl("https://www.w3schools.com/xml/note_error.xml")
    .then(validation => {
        console.log("example5")
        console.log(validation.isValid); // false
        console.log(validation.error); // https://www.w3schools.com/xml/note_error.xml:4:19: unexpected close tag.
    })

Methods

validate(content: string, type: XmlTypes = "application/xml")

Returns validation result of passed XML string using specified DOM type.

validateUrl(url: string)

Returns validation result of downloaded XML file from specified URL, DOM type asserts automaticly.

validateFile(url: string, type: XmlTypes = "application/xml")

Returns validation result of XML file from certain path (URL) using specified DOM type.

License

MIT - Made by tsziming

xml-validator's People

Contributors

tsziming avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.