node-xmllint is an Emscripten port of libxml2's `xmllint` utility, enabling XML and XSD schema validation directly within Node.js environments and web browsers. It provides a synchronous `validateXML` function that returns an object containing an `errors` array (or null if no errors). As of version 1.0.0, the package has not seen updates in approximately 8 years, indicating it is an abandoned project. Its key differentiator was bringing the battle-tested libxml2 C validation engine to JavaScript runtimes, supporting complex XML Schema Definitions directly, unlike simpler regex-based or DOM-parser-based validation methods available at the time. It was designed to integrate with older frontend bundling tools like Browserify via `browserify-shim` for browser usage. Newer, actively maintained alternatives exist that leverage WebAssembly for better performance and modern API design.
npm install node-xmllintVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `node-xmllint` to validate XML strings, both for well-formedness and against an XML Schema Definition (XSD). It shows cases for valid and invalid XML with and without schema validation.
Migrate to `xmllint-wasm` or a similar actively maintained library, which often uses WebAssembly and offers async validation. Example: `npm install xmllint-wasm` and adjust import/usage to its API.
For large XML payloads, process validation in a Node.js worker thread or switch to an asynchronous library (e.g., `xmllint-wasm`) if available. In browsers, consider a Web Worker.
If targeting browsers, consider if client-side validation is strictly necessary. If so, investigate more lightweight XML parsers or newer WASM-based solutions like `xmllint-wasm` that often have optimized sizes. Server-side validation is generally preferred for performance and security.
For ESM projects, use `import xmllint from 'node-xmllint';` with a compatible bundler/transpiler, or prefer an ESM-first alternative. Otherwise, ensure your project is configured for CommonJS or that your bundler correctly handles CJS modules.
Ensure you are using `const xmllint = require('node-xmllint');` and then calling `xmllint.validateXML(...)`. Verify the module is installed correctly (`npm install node-xmllint`).For browser use, ensure you are bundling with a tool like Browserify (with `browserify-shim` as suggested in the README). For Node.js ESM, consider an ESM-compatible alternative or refactor to use CommonJS modules if feasible.
Check your browser's Content-Security-Policy (CSP) headers; you might need to add `script-src 'unsafe-eval'` or `wasm-eval` directives. Ensure the WASM file is served with the correct MIME type (`application/wasm`). Consider using a library that employs asynchronous WASM loading (e.g., `xmllint-wasm`).
No dependency data recorded yet.