Installation
Purpose
This guide covers how to install Moxml and set up your chosen XML adapter for Ruby applications.
Basic installation
Add Moxml and your chosen XML adapter to your Gemfile:
# Gemfile
gem 'moxml'
# Choose one or more XML adapters:
gem 'nokogiri' # Recommended: Fast, widely used
gem 'libxml-ruby' # Alternative: Native performance
gem 'oga' # Pure Ruby: No C extensions
gem 'ox' # Fastest: Best for simple documents
# REXML is included in Ruby standard libraryThen install:
bundle installInstalling without Bundler
Install directly using gem:
gem install moxml
gem install nokogiri # Or your preferred adapterAdapter selection
Moxml automatically detects and uses available XML libraries. The default adapter priority order is:
-
Nokogiri (if available)
-
LibXML (if available)
-
Oga (if available)
-
REXML (always available)
-
Ox (if available)
You can override the default adapter in your application:
# Set default adapter globally
Moxml::Config.default_adapter = :libxml
# Or configure per instance
moxml = Moxml.new
moxml.config.adapter = :ogaVerifying installation
Test your installation:
require 'moxml'
# Check version
puts Moxml::VERSION
# Verify adapter loaded
context = Moxml.new
puts context.config.adapter.name
# => "Moxml::Adapter::Nokogiri" (or your adapter)
# Parse simple XML
doc = context.parse('<root><child>test</child></root>')
puts doc.root.name
# => "root"Troubleshooting
Gem not found:
Ensure bundler is using the correct gem source:
# Add to top of Gemfile
source 'https://rubygems.org'Adapter not loading:
If your chosen adapter isn’t loading:
-
Verify the adapter gem is installed:
bundle list | grep nokogiri -
Check for version conflicts:
bundle update moxml -
Try explicitly requiring:
require 'nokogiri'beforerequire 'moxml'
C extension compilation errors:
If Nokogiri or LibXML fail to install on your system, consider using pure Ruby adapters:
gem 'moxml'
gem 'oga' # Pure Ruby alternativeOr use REXML which requires no additional gems:
gem 'moxml'
# REXML is included in Ruby standard libraryNext steps
-
Quick start guide - Get started with basic usage
-
Learn about adapters - Understand adapter differences
-
Tutorials - Step-by-step learning paths