Adapters
Purpose
This section describes the supported XML adapters, their capabilities, and how to choose the right adapter for your needs.
What are adapters?
Moxml uses an adapter pattern to provide a unified interface over different XML processing libraries. Each adapter wraps a specific XML library (Nokogiri, LibXML, Oga, REXML, or Ox) and provides consistent behavior through Moxml’s API.
Available adapters
- Nokogiri adapter
-
Industry standard XML library with excellent performance and full XPath 1.0 support. Recommended for most use cases.
- LibXML adapter
-
Alternative to Nokogiri using native libxml2 bindings. Excellent performance with full feature support.
- Oga adapter
-
Pure Ruby XML parser with no C extensions. Ideal for JRuby, TruffleRuby, or environments where C extensions are not allowed.
- REXML adapter
-
Ruby standard library XML parser. Always available, requiring no additional gems. Best for maximum portability.
- Ox adapter
-
Fastest XML parser with minimal memory footprint. Best for simple documents and high-throughput scenarios.
Adapter comparison
Refer to the Compatibility matrix for detailed feature comparison across all adapters.
Switching adapters
Change adapters at runtime:
# Global default
Moxml::Config.default_adapter = :libxml
# Per instance
context = Moxml.new
context.config.adapter = :oga
# With configuration
moxml = Moxml.new do |config|
config.adapter = :nokogiri
config.strict_parsing = true
endNext steps
-
Explore individual adapter pages for detailed capabilities
-
Review the Compatibility matrix