oxml
🌐 EN , Change language
llms.txt

Documentation

Zero-Unsafe Architecture

Designed for maximum memory safety and performance: `#![forbid(unsafe_code)]`, arena allocation, and SIMD scanning.

Zero Unsafe Rule

oxml strictly enforces #![forbid(unsafe_code)] at crate root across all crates in the workspace. There are zero exceptions:

  • No raw pointer arithmetic
  • No unverified memory transmutes
  • No unchecked slice access

Every boundary check is verified at compile-time or hardware-accelerated without compromising memory safety.

Arena Allocation

oxml::Document backs its DOM with a generational slot-recycling node arena:

  • O(1) Node Lookup: Nodes are addressed via lightweight, copyable NodeId tokens.
  • Generational Recycling: Deleted nodes increment their slot generation counter. Accessing a stale NodeId safely fails rather than pointing to dangling or reallocated memory.
  • Cache Locality: Nodes are stored in contiguous vectors, maximizing CPU L1/L2 cache hit rates.

SWAR Acceleration

Safe delimiter scanning uses SIMD Within A Register (SWAR) across 8-byte chunks to scan character data and attribute values, delivering over +149% throughput vs scalar scanning without unsafe intrinsics.

Ecosystem Architecture

The oxml ecosystem is cleanly separated into specialized, decoupled crates that share the zero-unsafe core:

oxml Ecosystem Architecture Diagram Diagram showing the core oxml engine (Parser, DOM, XPath 1.0) branching out into six runtime integrations and tooling crates: oxml-cli, oxml-wasm, oxml-mcp, oxml-lsp, oxml-json, and xmlschema. RUNTIME INTEGRATIONS & TOOLING CORE ENGINE oxml Parser · Generational DOM · XPath 1.0 oxml-cli Terminal & CI/CD oxml-wasm Browser WebAssembly oxml-mcp AI Agent JSON-RPC oxml-lsp IDE Language Server oxml-json JSON / Streaming Converter xmlschema W3C XSD Conformance
Figure 1: Modular crate architecture sharing the zero-unsafe core engine.
View Mermaid source
graph TD
  subgraph Core["Core Engine"]
    OXML["oxml
(Parser, DOM, XPath 1.0)"] end subgraph Toolchain["Runtime Integrations & Tooling"] CLI["oxml-cli
(Terminal & CI/CD)"] WASM["oxml-wasm
(Browser WebAssembly)"] MCP["oxml-mcp
(AI Agent JSON-RPC)"] LSP["oxml-lsp
(IDE Language Server)"] JSON["oxml-json
(JSON/Streaming Converter)"] XSD["xmlschema
(W3C XSD Conformance)"] end OXML --> CLI OXML --> WASM OXML --> MCP OXML --> LSP OXML --> JSON OXML --> XSD

Zero-Copy Streaming Borrowing

For high-throughput pipelines where memory allocation overhead must be eliminated:

  • Reader::next_borrowed() yields BorrowedEvent<'a> items that borrow string slices directly from the internal input buffer.
  • Text nodes, tag names, and attribute values are inspected with zero heap copies.
  • Preserves bounded 34 KB memory usage while streaming multi-gigabyte documents at peak throughput.
Zero-Copy Streaming Borrowing Sequence Diagram Sequence diagram illustrating zero-copy streaming: Input Stream fills a 34 KB ring buffer, BorrowedEvent borrows a string slice with zero heap allocations, Application Logic inspects the slice, and the ring buffer pointer advances. Input Stream Multi-GB File/Socket Ring Buffer 34 KB Constant Cap BorrowedEvent<'a> &str Direct Slice Application Business Logic 1 Fill internal chunk 2 Borrow slice (&str, 0 heap alloc) 3 Inspect Tag / Attribute / Text 4 Release slice & advance ring pointer Zero Heap Copies · Bounded 34 KB Constant Memory Ceiling
Figure 2: Zero-copy streaming sequence with bounded 34 KB buffer borrowing.
View Mermaid source
sequenceDiagram
  autonumber
  participant Stream as Input Stream (Multi-GB)
  participant Ring as 34 KB Ring Buffer
  participant Event as BorrowedEvent (&str)
  participant App as Application Logic
  Stream->>Ring: Fill internal chunk
  Ring->>Event: Borrow slice without heap allocation
  Event->>App: Inspect Tag / Attribute / Text
  App-->>Ring: Release slice & advance ring buffer pointer