{"library":"node-xmllint","title":"XML Validation with xmllint (libxml2)","description":"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.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install node-xmllint"],"cli":null},"imports":["const xmllint = require('node-xmllint');","const { validateXML } = require('node-xmllint'); // Direct destructuring, assuming it's an object property\n// Or, more accurately based on docs: \nconst xmllint = require('node-xmllint');\nxmllint.validateXML(...);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const xmllint = require('node-xmllint');\n\nconst xmlValid = `<root><item id=\"1\"/></root>`;\nconst xmlInvalid = `<root><item></wrong></item></root>`;\nconst schemaValid = `<?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\" minOccurs=\"0\" maxOccurs=\"unbounded\">\\n          <xs:complexType>\\n            <xs:attribute name=\"id\" type=\"xs:integer\" use=\"optional\"/>\\n          </xs:complexType>\\n        </xs:element>\\n      </xs:sequence>\\n    </xs:complexType>\\n  </xs:element>\\n</xs:schema>`;\n\n// Validate valid XML without schema\nlet result = xmllint.validateXML({ xml: xmlValid });\nif (result.errors) {\n  console.error('Valid XML (no schema) validation errors:', result.errors);\n} else {\n  console.log('Valid XML (no schema) is well-formed.');\n}\n\n// Validate invalid XML without schema\nresult = xmllint.validateXML({ xml: xmlInvalid });\nif (result.errors) {\n  console.error('Invalid XML (no schema) validation errors:', result.errors);\n} else {\n  console.log('Invalid XML (no schema) is well-formed.');\n}\n\n// Validate valid XML against a schema\nresult = xmllint.validateXML({ xml: xmlValid, schema: schemaValid });\nif (result.errors) {\n  console.error('Valid XML (with schema) validation errors:', result.errors);\n} else {\n  console.log('Valid XML (with schema) is valid.');\n}\n\n// Validate invalid XML against a schema (e.g., missing 'id' attribute if required)\nconst xmlSchemaInvalid = `<root><item/></root>`;\nresult = xmllint.validateXML({ xml: xmlSchemaInvalid, schema: schemaValid });\nif (result.errors) {\n  console.error('Invalid XML (with schema) validation errors:', result.errors);\n} else {\n  console.log('Invalid XML (with schema) is valid.');\n}","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}