XML library written in TypeScript with multi-schema validation framework
- Complete API Documentation - Comprehensive guide with examples and API reference
- Quick Reference Guide - Cheat sheet for common operations and usage patterns
- Developer & AI Reference - Comprehensive technical reference with performance guidance and best practices
- Conformance Tests - W3C test suite integration for DTD and XML Schema validation testing
- Troubleshooting Guide - Common issues, solutions, and debugging techniques
- Type Definitions - TypeScript type definitions for better IDE support
TypesXML is available under two licenses: AGPL-3.0 for open source projects and a Commercial License for proprietary use. For commercial licensing inquiries, contact [email protected].
TypesXML implements XML 1.0/1.1 parsing with an extensible Grammar framework supporting multiple schema validation approaches. The library provides both SAX (event-driven) and DOM (tree-based) parsing with validation through a unified Grammar interface.
The Grammar interface provides schema validation support for:
- DTD Validation: Complete Document Type Definition support with full validation
- XML Schema: Comprehensive implementation with 76% W3C test suite success rate, including complex types, sequences, choices, and namespace-aware validation
- Enhanced XML Schema Support: Significant improvements to complex type validation, inheritance, and extension support
- Performance Improvements: Eliminated validation bottlenecks and optimized algorithms for better performance
- Enhanced Error Reporting: Detailed validation context with line/column information and improved error messages
- W3C Compliance: 76% success rate on official W3C XML Schema test suite (49,072/64,543 files)
- OASIS Catalog Support: Full XML Catalog resolution for DTD and entity references
- Entity Resolution: Built-in support for XML entities and catalog-based resolution
- Namespace Support: XML namespace handling with QualifiedName system
- Encoding Support: Various character encodings including UTF-8, UTF-16LE
- XML Writer: Utilities for writing XML documents with proper formatting
The SAX parser exposes methods through the ContentHandler interface:
initialize(): voidsetCatalog(catalog: Catalog): voidsetGrammar(grammar: Grammar): voidsetIncludeDefaultAttributes(include: boolean): voidstartDocument(): voidendDocument(): voidxmlDeclaration(version: string, encoding: string, standalone: string): voidstartElement(name: string, atts: Array<XMLAttribute>): voidendElement(name: string): voidinternalSubset(declaration: string): voidcharacters(ch: string): voidignorableWhitespace(ch: string): voidcomment(ch: string): voidprocessingInstruction(target: string, data: string): voidstartCDATA(): voidendCDATA(): voidstartDTD(name: string, publicId: string, systemId: string): voidendDTD(): voidskippedEntity(name: string): void
The DOMBuilder class implements the ContentHandler interface and builds a DOM tree from XML documents.
- XML 1.0/1.1 Parser: Full specification compliance with comprehensive error handling
- SAX Parser: Event-driven parsing for memory-efficient processing of large documents
- DOM Builder: Creates complete in-memory tree representation of XML documents
- OASIS Catalog Support: Full XML Catalog resolution for DTD and entity references
- Entity Resolution: Built-in support for XML entities and catalog-based resolution
- Namespace Support: Full XML namespace handling with QualifiedName system
- Extensible Grammar Interface: Unified abstraction supporting multiple schema types
- DTD Grammar: Complete Document Type Definition implementation
- XML Schema Support: Comprehensive implementation with complex type validation, inheritance, and namespace-aware processing
- Namespace-Aware Processing: QualifiedName system for namespace-aware validation
- Validation Context: Rich error reporting with line/column information
- Flexible Validation Modes: Configurable strictness levels for different use cases
- Optimized Performance: Enhanced validation algorithms with proper element consumption tracking
- DTD Grammar Implementation: Full parsing and validation of Document Type Definitions including element declarations, attribute lists, entities, and notations
- Content Model Processing: Complex content model parsing with sequences, choices, and cardinality validation
- Default Attribute Processing: Automatic setting of default attribute values from DTD declarations
- Internal and External Subset Processing: Complete DTD merging with proper precedence handling
- Enterprise-Grade Error Handling: Comprehensive validation with detailed error reporting
- XML Writer: Utilities for writing XML documents to files with proper formatting
- Indentation Support: Automatic indentation and prettification of XML documents
- W3C Compliance: Extensive testing against official W3C XML Test Suite with documented conformance results
- Conformance Testing: Integrated test runners for W3C DTD and XML Schema test suites
npm install typesxmlimport { ContentHandler } from "./ContentHandler";
import { DOMBuilder } from "./DOMBuilder";
import { SAXParser } from "./SAXParser";
import { XMLDocument } from "./XMLDocument";
import { XMLElement } from "./XMLElement";
export class Test {
constructor() {
try {
let contentHandler: ContentHandler = new DOMBuilder();
let xmlParser = new SAXParser();
xmlParser.setContentHandler(contentHandler);
// build the document from a file
xmlParser.parseFile("test.xml");
let doc: XMLDocument = (contentHandler as DOMBuilder).getDocument();
let root: XMLElement = doc.getRoot();
console.log(doc.toString());
// build the document again, this time from a string
xmlParser.parseString(doc.toString());
let newDoc : XMLDocument = (contentHandler as DOMBuilder).getDocument();
console.log(newDoc.toString());
} catch (error: any) {
if (error instanceof Error) {
console.log(error.message);
} else {
console.log(error);
}
}
}
}
new Test();