Registry / storage / xsd-validator

xsd-validator

JSON →
library1.1.1jsnpmunverified

xsd-validator is a lightweight Node.js library for validating XML documents against XSD schemas. Version 1.1.1 is the current stable release. It wraps libxmljs (libxml2 bindings) to perform schema validation. Key differentiators: simple API returning boolean for valid documents and Error arrays for invalid ones, no external XML parser dependency beyond libxml2, and first-class TypeScript support with shipped types. Release cadence is low; maintenance is driven by libxmljs updates. Unlike alternatives (e.g., xml-validator, libxmljs directly), it offers a focused validation-only API with zero configuration.

npm install xsd-validator
INSTALL
IMPORT
SIG · XSD-VALIDATOR
X
xsd-validator
storagejavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

validateSchema
import validateSchema from 'xsd-validator'
const validateSchema = require('xsd-validator')
Default ESM export; named imports not supported.
validateSchema (TypeScript)
import validateSchema from 'xsd-validator'
import { validateSchema } from 'xsd-validator'
The library exports a single default function.
validateSchema (CommonJS)
const validateSchema = require('xsd-validator').default
const validateSchema = require('xsd-validator')
In CommonJS, default export is under .default property.

Validates an XML document against an XSD schema, handling both valid and invalid cases.

import validateSchema from 'xsd-validator'; const xml = `<?xml version="1.0"?> <person> <name>John Doe</name> </person>`; const xsd = `<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>`; const result = validateSchema(xml, xsd); if (result === true) { console.log('XML is valid.'); } else { console.log('Validation errors:', result); }
Debug
Known issues
gotchalibxmljs native compilation requires build tools (C++ compiler, make). On Windows, may need windows-build-tools.
fix
Install build tools: on Ubuntu: build-essential; on macOS: Xcode CLI tools; on Windows: npm install --global windows-build-tools
affects: >=1.0.0
gotchaThe library may fail to load if libxml2 is not installed or version mismatched on the system.
fix
Ensure libxml2-dev (Ubuntu) or equivalent is installed. Alternatively, use a prebuilt binary via node-pre-gyp.
affects: >=1.0.0
gotchaError objects returned for invalid XML are native libxmljs error arrays, not standard Error instances.
fix
Handle result as either true or an array of objects with 'message', 'domain', etc.
affects: >=1.0.0
deprecatedNode.js versions below 14 are no longer supported.
fix
Upgrade Node.js to >=14.0.0
affects: >=1.0.0
Errors
Common errors & fixes
Error: Module parse failed: The keyword 'import' is reserved
Using ESM syntax in a CommonJS project without proper configuration.
fix
Set "type": "module" in package.json or use .mjs extension.
TypeError: validateSchema is not a function
Using CommonJS require without accessing .default property.
fix
Use const validateSchema = require('xsd-validator').default
Error: libxmljs.node: No such file or directory
Missing libxmljs native binding; may need recompilation.
fix
Run 'npm rebuild libxmljs' or 'npm install' again with build tools installed.
ValidationError: Element '...': No matching global declaration available for the validation root.
XML root element does not match the schema's target namespace.
fix
Ensure the XML and XSD have matching target namespaces or xmlns declarations.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
libxmljsrequiredBinds to libxml2 for parsing and schema validation
Agent activity
33 hits · last 30 days
node
28
Resources
xsd-validator — npm install xsd-validator · libregistry