xmloxide: A Safe, Fast XML/HTML Parser in Rust

xmloxide: A Safe, Fast XML/HTML Parser in Rust

Why xmloxide Stands Out

With libxml2 officially unmaintained since December 2025 and plagued by security vulnerabilities, developers need a modern alternative. Enter xmloxide—a pure Rust reimplementation of the XML/HTML parsing standard. This memory-safe library passes 100% of W3C XML conformance tests while outperforming libxml2 in serialization and XPath benchmarks.

Key Features

Memory Safety First

  • Arena-based DOM tree with zero unsafe code in public APIs
  • Self-contained Documents with Send + Sync support
  • Zero-copy string interning for fast comparisons

Comprehensive Parsing Capabilities

  • Multiple APIs: DOM, SAX2 streaming, XmlReader pull, push/incremental
  • HTML 4.01 parser with auto-closing and void element support
  • Robust error recovery for malformed XML

Performance Benchmarks

Serialization is 1.5-2.4x faster than libxml2 thanks to arena-based tree design. XPath queries run 1.1-2.7x faster across all benchmarks. For SVG documents, xmloxide achieves 12% better throughput.

Getting Started

use xmloxide::Document;

let doc = Document::parse_str("<root><child>Hello</child></root>").unwrap();
assert_eq!(doc.text_content(doc.root_element().unwrap()), "Hello");

C/C++ Integration

For legacy systems, xmloxide provides full C API compatibility. Migrate from libxml2 with drop-in replacements:

  • xmlReadMemoryDocument::parse_str
  • xmlFreeDocdrop(Document)
  • xmlNodeGetContentdoc.text_content()

Use Cases

Whether you need XML validation, XPath queries, or HTML parsing, xmloxide covers:

  1. 100% W3C XML conformance
  2. DTD/RelaxNG/XSD validation
  3. Canonical XML (C14N) serialization
  4. XInclude document inclusion

Try xmloxide Today

Replace libxml2 with a safer, faster alternative. Run cargo add xmloxide to start parsing XML/HTML with Rust’s memory guarantees. For C/C++ projects, build shared/static libraries with make and use the xmloxide.h header.