@anhquoc96/fastxml-schema
v0.1.2
Published
Schema validation contracts for fastxml.
Readme
@anhquoc96/fastxml-schema
Practical XSD validation and schema loading for fastxml.
The package is designed as a reusable validation layer for SOAP payloads, healthcare documents, ISO 20022 messages, UBL documents, and financial XML. Domain schemas are supplied by the application instead of bundled into this package.
Installation
npm install @anhquoc96/fastxml-schema @anhquoc96/fastxmlValidate a document
import { parse } from "@anhquoc96/fastxml";
import { parseXsd } from "@anhquoc96/fastxml-schema";
const schema = parseXsd(xsdText);
const document = parse(xmlText);
const result = schema.validate(document);
if (!result.valid) {
for (const issue of result.issues) {
console.error(issue.code, issue.path, issue.message);
}
}Load and cache a schema
import { XsdSchemaLoader } from "@anhquoc96/fastxml-schema";
const loader = new XsdSchemaLoader();
const schema = await loader.load("https://example.com/schema.xsd");SchemaCache can be supplied to XsdSchemaLoader when multiple document
validators share a schema lifecycle.
Current XSD coverage
- Global and local element declarations.
sequence,choice, andallmodel groups.- Simple and complex types.
- Required attributes and unknown attribute checks.
- Built-in string, boolean, numeric, date, dateTime, and URI types.
- Enumeration, pattern, length, and numeric facets.
- Structured issue codes and element paths.
Complete XSD 1.1 assertions, every XML Schema datatype, identity constraints,
substitution groups, and full import/include dependency resolution are not
yet covered. Test the exact schema version required by your deployment.
Development
npm run build --workspace @anhquoc96/fastxml-schema
npm run typecheck --workspace @anhquoc96/fastxml-schemaLicense
MIT License. See the package LICENSE file.
