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.2.0"
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?;
Official W3C XML Conformance Test Suite
babbel_xml is continuously tested against the official W3C XML Conformance Test Suite (XML TS 20130923).
Conformance Test Results
| Suite Name | Focus Area | Total Cases | Passed | Skipped | Pass Rate |
|---|---|---|---|---|---|
oasis |
OASIS XML 1.0 Conformance Suite | 348 | 348 | 0 | 100.0% |
xmltest |
James Clark XML Test Suite | 363 | 363 | 0 | 100.0% |
ibm/ibm_oasis_not-wf |
IBM / OASIS Not-Well-Formed Negative Suite | 424 | 424 | 0 | 100.0% |
eduni/errata-4e |
Edinburgh Univ. XML 1.0 (4th & 5th Edition Errata) | 392 | 392 | 0 | 100.0% |
ibm/ibm_oasis_valid |
IBM / OASIS Valid XML productions | 149 | 149 | 0 | 100.0% |
ibm/ibm_oasis_invalid |
IBM / OASIS Validity constraint rejections | 48 | 48 | 0 | 100.0% |
eduni/namespaces/1.0 |
Namespaces in XML 1.0 (Richard Tobin) | 48 | 48 | 0 | 100.0% |
eduni/errata-2e |
Edinburgh Univ. XML 1.0 (2nd Edition Errata) | 33 | 33 | 0 | 100.0% |
eduni/errata-3e |
Edinburgh Univ. XML 1.0 (3rd Edition Errata) | 13 | 13 | 0 | 100.0% |
japanese |
Japanese Character Set & Fatal Error Validations | 12 | 12 | 0 | 100.0% |
eduni/namespaces/errata-1e |
Edinburgh Univ. Namespaces in XML 1.0 Errata | 3 | 3 | 0 | 100.0% |
sun/sun-error |
Sun Microsystems Fatal Error Detection | 1 | 1 | 0 | 100.0% |
| OVERALL | Full W3C Conformance Corpus | 1,834 | 1,834 | 0 | 100.0% |
Running the Conformance Runner
# 1. Fetch test fixtures on demand (~20 MB uncompressed, uncommitted)
# On Linux/macOS: ./scripts/fetch_w3c_xmlts.sh
# 2. Run the 1,834 test cases
Documentation
See the Documentation Hub for full workspace guides:
- W3C XML Conformance Guide
- Architecture Guide
- Security Policy
- Development Guide
- Contributing Guidelines
License
Licensed under the MIT License.