{"id":17410,"library":"xmllint","title":"xmllint.js (libxml2 Emscripten Port)","description":"This package, `xmllint`, is an Emscripten port of `libxml2`'s `xmllint` command-line tool, enabling XML schema validation directly within Node.js environments and web browsers. It provides a JavaScript API, primarily `xmllint.validateXML`, to check XML against XSD or RelaxNG schemas. The current stable version is 0.1.1, which was last published to npm approximately 10 years ago. The package is largely unmaintained, with its GitHub repository showing minimal activity for several years. A key differentiator at the time of its release was bringing robust XML validation (from the native `libxml2`) to JavaScript without native bindings, relying instead on Emscripten compilation. Due to its abandonment, modern projects are advised to consider the actively maintained `xmllint-wasm` fork, which offers WebAssembly support, updated `libxml2` versions, and an expanded API.","status":"abandoned","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/kripken/xml.js","tags":["javascript"],"install":[{"cmd":"npm install xmllint","lang":"bash","label":"npm"},{"cmd":"yarn add xmllint","lang":"bash","label":"yarn"},{"cmd":"pnpm add xmllint","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package primarily targets CommonJS environments. While bundlers might process ESM imports, direct ESM usage without transpilation is unlikely to work due to the package's age and `browserify-shim` integration.","wrong":"import xmllint from 'xmllint';","symbol":"xmllint","correct":"const xmllint = require('xmllint');"},{"note":"The `xmllint` object is a default export containing the `validateXML` method. It is not a named export. Attempting to destructure `validateXML` directly will result in an undefined function.","wrong":"import { validateXML } from 'xmllint';","symbol":"validateXML","correct":"const xmllint = require('xmllint');\nxmllint.validateXML({ xml: '...', schema: '...' });"}],"quickstart":{"code":"const xmllint = require('xmllint');\n\nconst xmlString = `<root><item id=\"1\">Value 1</item><item id=\"2\">Value 2</item></root>`;\nconst validSchema = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n  <xs:element name=\"root\">\n    <xs:complexType>\n      <xs:sequence>\n        <xs:element name=\"item\" maxOccurs=\"unbounded\">\n          <xs:complexType>\n            <xs:simpleContent>\n              <xs:extension base=\"xs:string\">\n                <xs:attribute name=\"id\" type=\"xs:integer\" use=\"required\"/>\n              </xs:extension>\n            </xs:simpleContent>\n          </xs:complexType>\n        </xs:element>\n      </xs:sequence>\n    </xs:complexType>\n  </xs:element>\n</xs:schema>`;\nconst invalidSchema = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n  <xs:element name=\"root\">\n    <xs:complexType>\n      <xs:sequence>\n        <xs:element name=\"bad_item\" maxOccurs=\"unbounded\"/>\n      </xs:sequence>\n    </xs:complexType>\n  </xs:element>\n</xs:schema>`;\n\n// Example 1: Valid XML against a valid schema\nlet result1 = xmllint.validateXML({\n  xml: xmlString,\n  schema: validSchema\n});\n\nif (result1.errors) {\n  console.log('Validation 1 (Expected Pass) Errors:', result1.errors);\n} else {\n  console.log('Validation 1 (Expected Pass): No errors found.');\n}\n\n// Example 2: Invalid XML against a valid schema\nconst invalidXmlString = `<root><bad_item>This is wrong</bad_item></root>`;\nlet result2 = xmllint.validateXML({\n  xml: invalidXmlString,\n  schema: validSchema\n});\n\nif (result2.errors) {\n  console.log('Validation 2 (Expected Fail) Errors:', result2.errors[0]);\n} else {\n  console.log('Validation 2 (Expected Fail): No errors found (unexpected).');\n}\n\n// Example 3: Multiple schemas\nconst schemas = [\n  `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n  <xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://example.com/ns\" elementFormDefault=\"qualified\">\n    <xs:element name=\"document\" type=\"tns:DocumentType\"/>\n    <xs:complexType name=\"DocumentType\">\n      <xs:sequence>\n        <xs:element name=\"header\" type=\"tns:HeaderType\"/>\n      </xs:sequence>\n    </xs:complexType>\n  </xs:schema>`,\n  `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n  <xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:tns=\"http://example.com/ns\" targetNamespace=\"http://example.com/ns\" elementFormDefault=\"qualified\">\n    <xs:complexType name=\"HeaderType\">\n      <xs:sequence>\n        <xs:element name=\"title\" type=\"xs:string\"/>\n      </xs:sequence>\n    </xs:complexType>\n  </xs:schema>`\n];\nconst xmlWithMultipleSchemas = `<document xmlns=\"http://example.com/ns\"><header><title>My Document</title></header></document>`;\nlet result3 = xmllint.validateXML({\n  xml: xmlWithMultipleSchemas,\n  schema: schemas\n});\n\nif (result3.errors) {\n  console.log('Validation 3 (Multiple Schemas - Expected Pass) Errors:', result3.errors);\n} else {\n  console.log('Validation 3 (Multiple Schemas - Expected Pass): No errors found.');\n}","lang":"javascript","description":"Demonstrates how to use `xmllint.validateXML` to validate XML strings against single or multiple XSD schemas, showcasing both successful and erroneous validation scenarios."},"warnings":[{"fix":"Migrate to `xmllint-wasm`. This typically involves `npm uninstall xmllint` and then `npm install xmllint-wasm`. Note that `xmllint-wasm` has a different API and requires Node.js 16+ or modern browsers with WebAssembly support.","message":"The `xmllint` package (kripken/xml.js) is effectively abandoned, with its last npm publish over 10 years ago and minimal GitHub activity for years. There will be no further updates, bug fixes, or security patches. Users are strongly advised to migrate to the `xmllint-wasm` fork, which is actively maintained, uses WebAssembly, and supports newer libxml2 versions.","severity":"breaking","affected_versions":">=0.1.1"},{"fix":"For new projects or existing projects sensitive to bundle size, consider `xmllint-wasm` which outputs WebAssembly, resulting in a smaller combined library size (around 860KB for wasm and JS wrappers). Alternatively, explore server-side validation or more lightweight JavaScript XML parsing/validation libraries if your use case permits.","message":"As an Emscripten port of a C library, `xmllint` can contribute significantly to JavaScript bundle size, impacting application load times and performance, especially in browser environments. This is compounded by the fact it outputs asm.js, not WebAssembly, further increasing bundle size compared to modern alternatives.","severity":"gotcha","affected_versions":">=0.1.1"},{"fix":"Ensure your build tooling (e.g., Webpack, Rollup) is configured to handle CommonJS modules when consuming this package. If you are using native ESM, you will likely need a transpilation step. For modern applications, `xmllint-wasm` offers better ESM compatibility.","message":"The package was designed for older JavaScript module systems, primarily CommonJS, and explicitly mentions compatibility with Browserify via `browserify-shim`. Using it directly with modern ESM `import` statements in environments without transpilation or with modern bundlers (like Webpack 5+ or Rollup) might require specific configuration or may not work as expected without a proper CJS-to-ESM bridge.","severity":"gotcha","affected_versions":">=0.1.1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"If in a Node.js CJS environment, ensure `const xmllint = require('xmllint');` is used. In a browser or ESM context, ensure your bundler is correctly configured to handle CommonJS modules. Consider migrating to `xmllint-wasm` for better ESM support.","cause":"Attempting to use `xmllint` in a modern ESM context without proper CommonJS interoperability or before the module has been loaded.","error":"ReferenceError: xmllint is not defined"},{"fix":"Verify that you are importing the entire `xmllint` module as a default (CommonJS `require`) and then calling the `validateXML` method on the imported object, e.g., `const xmllint = require('xmllint'); xmllint.validateXML(...)`.","cause":"This error typically occurs when `xmllint` is imported incorrectly, perhaps as a named import when it's a default export containing the method, or if the `xmllint` object itself is undefined.","error":"TypeError: xmllint.validateXML is not a function"},{"fix":"For large XML files or performance-critical applications, consider using `xmllint-wasm`, which has introduced `--stream` option support and uses WebAssembly for improved performance and efficiency. Alternatively, offload validation to a server-side process using a native `xmllint` executable or a purpose-built XML parser.","cause":"The original `xmllint.js` package processes XML in a non-streaming fashion and as an Emscripten-compiled asm.js module, it can be less performant and memory-intensive for very large XML documents.","error":"XML schema validation not working for large XML files or slow performance."}],"ecosystem":"npm","meta_description":null}