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

node-libxml

v5.0.6

Published

Check Wellformed, DTD validity & get Xpath from pure node addons

Downloads

1,780

Readme

Node-LibXML

For old node.js versions please use verison < 4.0.0 Already for old LTS node (4,6,8) npm install [email protected];

For new node.js versions (10,12,14,16,18,20) we are using n-api so please install npm install [email protected], its compatible with arm proc too for version >= 16 (you wil notice a free memoery message when using free memory function after node >16) 🙂

Node-Libxml is a LibXML2 Node.js Wrapper

It can perform:

  • Wellformed check & rerror report
  • Validity against DTD/XSD(Schema) check,
  • Get doctype informations (about dtd)
  • GetXpath Values
  • Load XMl from string or file path

Requirements:

Node-Libxml has nos any dependencies, it's fully bundled, so you can just use it as it comes :)

Works on : Linux, Osx & Windows (no 32bits, just 64 bits)

Why use it

Node-libxml has been thought differently than libxmljs; whereas libxmljs can be use in commun uses, you can use node-libxml if:

  • You wan to validate against DTD (libxmljs can't)
  • You want a silent program if xml is not wellformed (node-libxml returns wellformed error in object; libxmljs throws)
  • You want to do xml processing in parallel forks
  • You want to load XML from file path OR string
  • You want to validate against DTD / schema on multiple documents with just ONE dtd/schema loaded in memory (libxmljs loads it on each validation request), so it's clearly by far fastest!

Install

  npm i node-libxml

Use

  const Libxml = require('node-libxml').Libxml; // or import {Libxml} from 'node-libxml'
  let libxml = new Libxml();

  let xmlIsWellformed = libxml.loadXml('path/to/xml');
  let xmlIsWellformedStr = libxml.loadXmlFromString('<name>test</name>');

  console.log(xmlIsWellformed);
  console.log(libxml.wellformedErrors);

  console.log(libxml.getDtd());

  libxml.loadDtds(['path/to/dtd1', 'path/to/dtd2']);
  let xmlIsValid = libxml.validateAgainstDtds();
  console.log(xmlIsValid);
  console.log(libxml.validationDtdErrors);

  //Get some xpaths;
  let aRandomPathBoolean = libxml.xpathSelect('boolean(//some/path'));
  let aRandomPathNumber = libxml.xpathSelect('number(//some/path'));
  let countSomeElements = libxml.xpathSelect('count(//some/path'));
  //... & all xpath could do I think

check tests for more examples

API

Loading functions

loadXml(string)

A function of libxml to load the XML file TAKE a path & RETURN true if wellformed | false if not SET a an array 'wellformedErrors' in libxml element containing wellformed errors

loadXmlFromString(string)

A function of libxml to create the xml Dom from a string TAKE a string containing xml & RETURN true if wellformed | false if not SET a an array 'wellformedErrors' in libxml element containing wellformed errors

loadDtds(array)

A function of libxml to load the DTDs files TAKE an array of path of & RETURN nothing SET a an array 'dtdsLoadedErrors' in libxml element IF error happend on loading dtd(s)

loadSchemas(array)

A function of libxml to load the XSDs files TAKE an array of path of & RETURN nothing SET a an array 'schemasLoadedErrors' in libxml element IF error happend on loading xsd(s) ex

Validating functions

validateAgainstDtd()

A function of libxml to validate against the previously loaded DTD(s) TAKE nothing & RETURN a string which is the name of the first dtd which has validated RETURN false if no dtd(s) have validate the xml RETURN null if no any dtd have been corectly loaded SET a an array 'validationDtdErrors' in libxml element if no dtd has validate

validateAgainstSchemas()

A function of libxml to validate against the previously loaded DTD(s) TAKE nothing & RETURN a string which is the name of the first dtd which has validated RETURN false if no dtd(s) have validate the xml RETURN null if no any schema have been corectly loaded SET a an array 'validationDtdErrors' in libxml element if no dtd has validate

Get informations of the the XML

getDtd()

A function of libxml to evaluate the xpath on the previously loaded XML TAKE nothin & RETURN an object containing name,externalId & systemId

xpathSelect(string)

A function of libxml to evaluate the xpath on the previously loaded XML TAKE string & RETURN value depending on what you asked (number, boolean..) RETURN null if no match ex

Memory management

Use those functions when you have finished jobs of elements, or before overwrite them. ex

freeXml()

A function of libxml to free XML memory file TAKE nothing & RETURN nothin FREE memory & clear 'wellformedErrors' property on libxml instance

freeDtds()

A function of libxml to free all the DTD in memory TAKE nothing & RETURN nothin FREE memory & clear 'dtdsLoadedErrors' property on libxml instance FREE memory & clear 'validationDtdErrors' property on libxml instance

freeSchemas()

A function of libxml to free all the Schema in memory TAKE nothing & RETURN nothin FREE memory & clear 'schemasLoadedErrors' property on libxml instance FREE memory & clear 'validationSchemaErrors' property on libxml instance

clearAll()

A function of libxml to free all the memory taken by libxml2 TAKE nothing & RETURN nothin free all memory in all instance in all fork using by libxml.

Contribute

Install

  • npm i
  • npm test should pass 😎
  • npm run publish

Important notes

Travis & appveyor cannot be used anymore with n-api because auto-publish from node-pre-gyp-github not working anymore + we have now n release for one node version