npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

w3c-xml-validator

v1.1.0

Published

A library for programmatically submitting XML for online validation using W3C's Markup Validation Service (https://validator.w3.org/check).

Downloads

2,489

Readme

w3c-xml-validator

Linux Build Status Windows Build Status Coverage Status

A Node.js library for programmatically confirming whether a given XML document is both well-formed and valid according to the specified DTD.

This project adheres to the standard coding style (click below for more information):

js-standard-style

Why?

I was frustrated by the lack of programmatic options for validating XML with JavaScript...in particular, for validating against a public DTD. I realize that there may not be a big need for this across the Node.js community as a whole, but nonetheless it is something I required, so I built this.

W3C

This library relies on the online validator provided by W3C. Please consider donating to the W3C if you find this library useful, because without their tools, this one wouldn't exist. Click on the logo below:

Donate to W3C

Programmatic Use

This module exports a function that accepts a single value: the XML to be validated. The XML must contain a !DOCTYPE element with an publicly-accessible DTD. The return value is a Promise that will be fulfilled or rejected with the values described below.

Example:

const validate = require('w3c-xml-validator')
const xml = '<?xml version="1.0" encoding="utf-8"?>...'

validate(xml)
    .then(function (response) {
        // the response will contain a basic is/is not valid flag, plus warnings and errors (if present)
    })
    .catch(function (err) {
        // the promise may be rejected for any of the reasons listed below
    })

Fulfillment

When the promise is fulfilled, the returned value will be a plain object with the following properties:

| Key | Data type | Notes | |-----|-----------|-------| | doctype | {String} | The DTD that the validator used. | | isValid | {Boolean} | A simple yes/no based on the results from the W3C validation tool. | | warnings | {Array} of {String} | This is a list of the entries under "Notes and Potential Issues". Each value is the entry title, not the verbose description. | | errors | {Array} of {String} | This is a list of the entries under "Validation Output: # Error(s)". Each value is the entry title that appears in bold, not the verbose description. |

isValid will have the same value as (errors.length === 0). warnings may have entries, even if the validation is successful.

Rejection

The promise may be rejected for any of the following reasons:

  • The input parameter is undefined, null, or an empty string.
  • The W3C web site is not reachable.
  • The W3C web site is not functioning (for example, returns a 5xx HTTP status code).
  • The code in this library has a bug that causes the W3C web site to return a 3xx or 4xx HTTP status code.

Check the message property of the error object to find out more information about the source of the problem. If you feel there is an issue with the code in this project, please submit a ticket on GitHub for help.

Command Line Use

This library can also be called from the command line. The XML to validate can either be piped into the library:

$ cat file-to-validate.xml | w3c-xml-validator

or the file name provided as an argument:

$ w3c-xml-validator file-to-validate.xml

The exit code will be non-zero if isValid === false. Any rejections will be output to stderr.

License

Please refer to LICENSE.