babbel_xml
A robust, full-featured pure Rust XML toolkit providing W3C-compliant DOM construction, validating SAX/pull-parser, W3C Canonical XML (C14N 1.0/1.1), DTD validation, XSD schema validation, and an XPath 1.0 query engine. Backed by the unified babbel_core streaming I/O architecture.
Features
- W3C XML DOM Engine:
- Full support for elements, text nodes, CDATA sections, comments, and processing instructions.
- Complete XML Namespaces (XMLNS) resolution and prefix inheritance.
- Serialization with customizable indentation, attribute sorting, and entity escaping.
- W3C Canonical XML (C14N 1.0 & 1.1):
- Canonicalize documents and subtrees for cryptographic signature verification.
- Handles namespace prefix rewrites, attribute ordering, and character normalization.
- Validation:
- DTD Validation: Element content models, attribute types (
CDATA,ID,IDREF), and entity expansion limits. - XSD Schema Validator: Simple types, complex types, sequences, choices, and facet validation.
- DTD Validation: Element content models, attribute types (
- XPath 1.0 Engine:
- Full XPath 1.0 expression evaluator with predicate filters, axes (
child,descendant,attribute,parent), and core function library (count,string,concat,contains,starts-with,substring).
- Full XPath 1.0 expression evaluator with predicate filters, axes (
- Security Hardening:
- Billion Laughs exponential entity expansion mitigation.
- Configurable nesting depth and text node limits to prevent unbounded memory allocation.
- Unified Streaming I/O:
- Implements
ICharStream,IRewindable,ILocationAware,IClearable, andITailInspectablefrombabbel_core::io.
- Implements
no_stdSupport:- Operates in memory-constrained environments with the
allocfeature.
- Operates in memory-constrained environments with the
Installation
Add to your Cargo.toml:
[]
= "0.1.1"
Or as a workspace path dependency:
[]
= { = "crates/xml" }
Feature Flags
| Feature | Default | Description |
|---|---|---|
std |
Yes | Standard library file I/O and stream reading. |
alloc |
Yes (via std) |
Heap allocation primitives for no_std environments. |
dtd |
Yes | DTD parsing and document validation engine. |
xsd |
Yes | XSD schema compilation and validation. |
xpath |
Yes | XPath 1.0 expression evaluator. |
stringify |
Yes | XML serialization and C14N canonicalization. |
serde |
No | Serde derive support for XML data structures. |
Quickstart
1. Parsing & DOM Navigation
use Document;
2. XPath 1.0 Queries
use Document;
3. Canonical XML (C14N)
use canonicalize;
use Document;
4. Streaming I/O with babbel_core
use ;
use ;
Security Limits
babbel_xml provides built-in defenses against malicious XML payloads:
max_depth: Limits nesting to prevent stack overflows (default: 256).max_entity_expansions: Mitigates Billion Laughs exponential entity expansion (default: 10,000).max_stream_size: Limits unbounded streaming inputs (default: 50 MB).
use XmlSource;
// Read streaming input with a custom safety limit (10 MB)
let file = open?;
let source = from_reader_with_limit?;
Documentation
See the Documentation Hub for full workspace guides:
License
Licensed under the MIT License.