https://github.com/sferik/multi_xml
A generic swappable back-end for XML parsing
https://github.com/sferik/multi_xml
Keywords from Contributors
rubygems rack mvc activerecord activejob github-api octokit-rb rspec sinatra sidekiq
Last synced: about 16 hours ago
JSON representation
Repository metadata
A generic swappable back-end for XML parsing
- Host: GitHub
- URL: https://github.com/sferik/multi_xml
- Owner: sferik
- License: mit
- Created: 2010-10-03T05:18:16.000Z (over 15 years ago)
- Default Branch: main
- Last Pushed: 2026-05-04T18:31:37.000Z (19 days ago)
- Last Synced: 2026-05-20T00:37:41.823Z (4 days ago)
- Language: Ruby
- Homepage:
- Size: 550 KB
- Stars: 161
- Watchers: 4
- Forks: 39
- Open Issues: 0
- Releases: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
README.md
MultiXML
Lots of Ruby libraries parse XML and everyone has their favorite XML parser.
Instead of choosing a single XML parser and forcing users of your library to
be stuck with it, you can use MultiXML instead, which will simply choose the
fastest available XML parser. Here's how to use it:
require "multi_xml"
MultiXML.parse("<tag>contents</tag>") #=> {"tag" => "contents"}
MultiXML.parse("<tag>contents</tag>", symbolize_names: true) #=> {tag: "contents"}
MultiXML.parse returns {} for empty and whitespace-only inputs instead of
raising, so a missing or blank payload is observable as an empty hash rather
than an exception. When parsing invalid XML, MultiXML will throw a
MultiXML::ParseError.
begin
MultiXML.parse("<open></close>")
rescue MultiXML::ParseError => exception
exception.xml #=> "<open></close>"
exception.cause #=> Nokogiri::XML::SyntaxError: ...
end
Deprecated in 0.9.0
The module constant, the primary parse entry point, and the
symbolize-keys option were renamed to align MultiXML with MultiJSON
and Ruby stdlib JSON.parse. The old names still work in 0.x but
now emit a one-time deprecation warning; they will be removed in 1.0.
| Deprecated | Use instead |
|---|---|
MultiXml (constant) |
MultiXML (all-caps) |
MultiXML.load(xml) |
MultiXML.parse(xml) |
symbolize_keys: option |
symbolize_names: option |
The MultiXml constant (CamelCase) continues to work as a thin
delegator; every method call, constant lookup, and rescue clause
routes through MultiXML transparently.
ParseError instances expose xml and cause readers. xml contains the
input that caused the problem; cause contains the original exception raised
by the underlying parser.
Writing a custom parser
A custom parser is any class (or module) that responds to two class methods:
class MyParser
def self.parse(io, namespaces: :strip)
# parse the IO-like object into a Hash, raising ParseError on failure
end
def self.parse_error
MyParser::ParseError
end
end
MultiXML.parser = MyParser
parse_error is required: MultiXML.parse rescues MyParser.parse_error
to wrap parse failures in MultiXML::ParseError. The built-in parsers in
lib/multi_xml/parsers/ are working examples.
MultiXML tries to have intelligent defaulting. If any supported library is
already loaded, MultiXML uses it before attempting to load others. When no
backend is preloaded, MultiXML walks its automatic preference list and uses the first
one that loads successfully:
This is the library's built-in default selection order, not a guarantee that
the list is globally fastest for every workload. Real-world performance depends
on the document shape and the Ruby implementation, and the benchmark suite
below also measures SAX backends that are not part of automatic parser
detection. REXML is a Ruby default gem, so it's always available as a
last-resort fallback on any supported Ruby. If you have a workload where a
different backend is faster, set it explicitly with
MultiXML.parser = :your_parser.
Benchmarking Parsers
This repo includes a benchmark suite that compares every available built-in
backend across multiple XML shapes and sizes instead of relying on a single
synthetic document. The workloads cover:
- shallow and wide XML
- deeply nested XML
- record batches with repeated siblings
- attribute-dense elements
- mixed-content sections
- namespace-heavy feeds
- a large catalog-style document
Run the full benchmark with:
bundle exec rake benchmark
You can also run the script directly for shorter runs or Markdown-friendly
output:
bundle exec ruby benchmark.rb --quick
bundle exec ruby benchmark.rb --format=markdown
The output includes:
- a single best-overall parser based on the equal-weight geometric mean of
per-scenario relative throughput - an overall ranking table for every parser
- a scenario matrix showing which parser won each workload
- an exclusions table when a parser crashes or produces mismatched output on a
valid workload
Allocation efficiency is reported as a secondary metric using allocated Ruby
objects per parse so ties on throughput are easier to interpret.
PARSER_PREFERENCE drives auto-detection (see "Configuration" above) and is
ordered fastest-first per the benchmark suite. CI re-runs the benchmark on
each supported runtime and fails if the observed ranking diverges from this
table:
| rank | CRuby/MRI | JRuby | TruffleRuby |
|---|---|---|---|
| 1 | ox |
— | — |
| 2 | libxml |
— | rexml |
| 3 | nokogiri |
nokogiri |
libxml |
| 4 | oga |
— | oga |
| 5 | rexml |
rexml |
nokogiri |
A dash means the parser isn't usable on that runtime. ox has no JRuby
build and is filtered out of TruffleRuby auto-detection (its SAX callbacks
miscompile under the JIT after warmup); libxml-ruby has no JRuby build;
oga 3.x crashes on JRuby 10 (its precompiled Java backend was built
against an older JRuby API). TruffleRuby's JIT inverts the FFI-vs-pure-Ruby
tradeoff for the remaining backends, so rexml rises to the top and
nokogiri falls to last.
Supported Ruby Versions
This library aims to support and is tested against the following Ruby
implementations:
- Ruby 3.2
- Ruby 3.3
- Ruby 3.4
- Ruby 4.0
- JRuby 10.0 (targets Ruby 3.4 compatibility)
- TruffleRuby 33.0 (native and JVM)
If something doesn't work in one of these implementations, it's a bug.
This library may inadvertently work (or seem to work) on other Ruby
implementations, however support will only be provided for the versions listed
above.
If you would like this library to support another Ruby version, you may
volunteer to be a maintainer. Being a maintainer entails making sure all tests
run and pass on that implementation. When something breaks on your
implementation, you will be responsible for providing patches in a timely
fashion. If critical issues for a particular implementation exist at the time
of a major release, support for that Ruby version may be dropped.
Versioning
This library aims to adhere to Semantic Versioning 2.0.0. Violations
of this scheme should be reported as bugs. Specifically, if a minor or patch
version is released that breaks backward compatibility, that version should be
immediately yanked and/or a new version should be immediately released that
restores compatibility. Breaking changes to the public API will only be
introduced with new major versions. As a result of this policy, you can (and
should) specify a dependency on this gem using the Pessimistic Version
Constraint with two digits of precision. For example:
spec.add_dependency "multi_xml", "~> 0.9"
Copyright
Copyright (c) 2010-2026 Erik Berlin. See LICENSE for details.
Owner metadata
- Name: Erik Berlin
- Login: sferik
- Email:
- Kind: user
- Description: Maker, Breaker
- Website:
- Location: San Francisco
- Twitter: sferik
- Company: @twitter
- Icon url: https://avatars.githubusercontent.com/u/10308?u=5a2785be9d9bf021907c5c53dc1345edd137604c&v=4
- Repositories: 180
- Last ynced at: 2023-04-09T03:48:45.493Z
- Profile URL: https://github.com/sferik
GitHub Events
Total
- Delete event: 8
- Issues event: 4
- Watch event: 4
- Issue comment event: 4
- Push event: 49
- Pull request review event: 1
- Pull request review comment event: 1
- Create event: 3
Last Year
- Delete event: 8
- Issues event: 2
- Watch event: 3
- Issue comment event: 3
- Push event: 45
- Pull request review event: 1
- Pull request review comment event: 1
- Create event: 2
Committers metadata
Last synced: 1 day ago
Total Commits: 437
Total Committers: 24
Avg Commits per committer: 18.208
Development Distribution Score (DDS): 0.151
Commits in past year: 74
Committers in past year: 2
Avg Commits per committer in past year: 37.0
Development Distribution Score (DDS) in past year: 0.027
| Name | Commits | |
|---|---|---|
| Erik Michaels-Ober | s****k@g****m | 371 |
| Peter Ohler | o****r@m****m | 16 |
| Nathan Sutton | n****e@z****m | 6 |
| phiggins | p****e@p****g | 6 |
| Josh Kalderimis | j****s@g****m | 4 |
| meganemura | m****e@g****m | 3 |
| Earlopain | 1****n | 3 |
| Hakan Ensari | me@h****m | 3 |
| Koichi ITO | k****o@g****m | 3 |
| Sebastian Staudt | k****r@g****m | 3 |
| Andrey Koleshko | k****5@g****m | 2 |
| Bill Fisher | f****v@g****m | 2 |
| Jack Pearkes | j****t@g****m | 2 |
| Olle Jonsson | o****n@g****m | 2 |
| sue445 | s****5@s****t | 2 |
| Brian Shirai | b****n@g****m | 1 |
| František Dvořák | v****i@c****z | 1 |
| Sergey Avseyev | s****v@g****m | 1 |
| Steve Agalloco | s****o@g****m | 1 |
| Tom Cocca | t****a@g****m | 1 |
| Yorick Peterse | y****e@g****m | 1 |
| David Judd | d****d@a****u | 1 |
| Trevor Rowe | t****e@g****m | 1 |
| guycall | g****l | 1 |
Committer domains:
- academia.edu: 1
- civ.zcu.cz: 1
- sue445.net: 1
- hakanensari.com: 1
- peterhiggins.org: 1
- zencoder.com: 1
- mac.com: 1
Issue and Pull Request metadata
Last synced: 3 days ago
Total issues: 33
Total pull requests: 44
Average time to close issues: over 3 years
Average time to close pull requests: 11 months
Total issue authors: 23
Total pull request authors: 29
Average comments per issue: 1.55
Average comments per pull request: 1.91
Merged pull request: 34
Bot issues: 0
Bot pull requests: 0
Past year issues: 2
Past year pull requests: 2
Past year average time to close issues: about 14 hours
Past year average time to close pull requests: 1 day
Past year issue authors: 2
Past year pull request authors: 2
Past year average comments per issue: 1.0
Past year average comments per pull request: 0.0
Past year merged pull request: 2
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- sferik (8)
- morgoth (2)
- trevorrowe (2)
- tcocca (2)
- tcollier (1)
- noraj (1)
- DannyBen (1)
- graaff (1)
- dbwinger (1)
- jkr2255 (1)
- sylvain-8422 (1)
- tfwright (1)
- grosser (1)
- boutil (1)
- fisherwebdev (1)
Top Pull Request Authors
- ohler55 (4)
- phiggins (3)
- olleolleolle (3)
- koraktor (3)
- koic (3)
- Earlopain (2)
- VitaliySerov (2)
- andymai (2)
- ka8725 (2)
- avsej (1)
- leocwolter (1)
- hakanensari (1)
- yorickpeterse (1)
- brixen (1)
- pearkes (1)
Top Issue Labels
Top Pull Request Labels
Package metadata
- Total packages: 14
-
Total downloads:
- rubygems: 1,131,830,739 total
- Total docker downloads: 1,402,371,248
- Total dependent packages: 293 (may contain duplicates)
- Total dependent repositories: 102,860 (may contain duplicates)
- Total versions: 98
- Total maintainers: 1
- Total advisories: 1
gem.coop: multi_xml
Provides swappable XML backends utilizing LibXML, Nokogiri, Ox, or REXML.
- Homepage: https://github.com/sferik/multi_xml
- Documentation: http://www.rubydoc.info/gems/multi_xml/
- Licenses: MIT
- Latest release: 0.9.1 (published 19 days ago)
- Last Synced: 2026-05-20T15:03:48.214Z (3 days ago)
- Versions: 29
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 566,036,490 Total
- Docker Downloads: 701,185,624
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.014%
- Downloads: 0.043%
- Maintainers (1)
-
Funding:
- https://github.com/sponsors/sferik
ubuntu-20.04: ruby-multi-xml
- Homepage: https://github.com/sferik/multi_xml
- Licenses: mit
- Latest release: 0.6.0-1 (published 3 months ago)
- Last Synced: 2026-03-13T14:28:11.040Z (2 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.59%
- Forks count: 0.938%
- Stargazers count: 1.422%
rubygems.org: multi_xml
Provides swappable XML backends utilizing LibXML, Nokogiri, Ox, or REXML.
- Homepage: https://github.com/sferik/multi_xml
- Documentation: http://www.rubydoc.info/gems/multi_xml/
- Licenses: MIT
- Latest release: 0.9.1 (published 19 days ago)
- Last Synced: 2026-05-19T23:01:24.576Z (4 days ago)
- Versions: 29
- Dependent Packages: 293
- Dependent Repositories: 102,860
- Downloads: 565,794,249 Total
- Docker Downloads: 701,185,624
-
Rankings:
- Downloads: 0.042%
- Dependent repos count: 0.118%
- Dependent packages count: 0.146%
- Docker downloads count: 0.179%
- Average: 1.544%
- Forks count: 4.285%
- Stargazers count: 4.493%
- Maintainers (1)
-
Funding:
- https://github.com/sponsors/sferik
- Advisories:
proxy.golang.org: github.com/sferik/multi_xml
- Homepage:
- Documentation: https://pkg.go.dev/github.com/sferik/multi_xml#section-documentation
- Licenses: mit
- Latest release: v0.9.1 (published 19 days ago)
- Last Synced: 2026-05-19T03:03:06.166Z (5 days ago)
- Versions: 29
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 5.503%
- Average: 5.688%
- Dependent repos count: 5.872%
ubuntu-23.04: ruby-multi-xml
- Homepage: https://github.com/sferik/multi_xml
- Licenses:
- Latest release: 0.6.0-1 (published 3 months ago)
- Last Synced: 2026-03-11T14:11:11.638Z (2 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-10: ruby-multi-xml
- Homepage: https://github.com/sferik/multi_xml
- Documentation: https://packages.debian.org/buster/ruby-multi-xml
- Licenses:
- Latest release: 0.6.0-1 (published 3 months ago)
- Last Synced: 2026-03-14T02:08:06.999Z (2 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-11: ruby-multi-xml
- Homepage: https://github.com/sferik/multi_xml
- Documentation: https://packages.debian.org/bullseye/ruby-multi-xml
- Licenses:
- Latest release: 0.6.0-1 (published 3 months ago)
- Last Synced: 2026-03-14T07:16:35.609Z (2 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-23.10: ruby-multi-xml
- Homepage: https://github.com/sferik/multi_xml
- Licenses:
- Latest release: 0.6.0-1 (published 3 months ago)
- Last Synced: 2026-03-14T03:15:10.541Z (2 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-22.04: ruby-multi-xml
- Homepage: https://github.com/sferik/multi_xml
- Licenses:
- Latest release: 0.6.0-1 (published 3 months ago)
- Last Synced: 2026-03-13T22:39:07.242Z (2 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
guix: ruby-multi-xml
Swappable XML backends for Ruby
- Homepage: https://github.com/sferik/multi_xml
- Documentation: https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/ruby-xyz.scm#n6070
- Licenses: expat
- Latest release: 0.6.0 (published 3 months ago)
- Last Synced: 2026-04-27T16:17:57.625Z (26 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-12: ruby-multi-xml
- Homepage: https://github.com/sferik/multi_xml
- Documentation: https://packages.debian.org/bookworm/ruby-multi-xml
- Licenses:
- Latest release: 0.6.0-1 (published 3 months ago)
- Last Synced: 2026-03-13T23:45:36.666Z (2 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-24.10: ruby-multi-xml
- Homepage: https://github.com/sferik/multi_xml
- Licenses:
- Latest release: 0.6.0-1 (published 3 months ago)
- Last Synced: 2026-03-09T17:08:32.213Z (3 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
ubuntu-24.04: ruby-multi-xml
- Homepage: https://github.com/sferik/multi_xml
- Licenses:
- Latest release: 0.6.0-1 (published 4 months ago)
- Last Synced: 2026-03-06T16:49:48.519Z (3 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
debian-13: ruby-multi-xml
- Homepage: https://github.com/sferik/multi_xml
- Documentation: https://packages.debian.org/trixie/ruby-multi-xml
- Licenses:
- Latest release: 0.6.0-1 (published 3 months ago)
- Last Synced: 2026-03-14T18:10:40.347Z (2 months ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 100%
Dependencies
- backports >= 0 development
- coveralls >= 0 development
- kramdown >= 0 development
- pry >= 0 development
- rspec >= 3 development
- rubocop >= 0.47 development
- simplecov >= 0.9 development
- yardstick >= 0 development
- libxml-ruby >= 0
- nokogiri >= 0
- oga >= 2.3
- ox >= 0
- rake >= 0
- yard >= 0
- bundler ~> 1.0 development
- actions/checkout v4 composite
- ruby/setup-ruby v1 composite
- actions/checkout v4 composite
- ruby/setup-ruby v1 composite
- actions/checkout v4 composite
- ruby/setup-ruby v1 composite
- actions/checkout v4 composite
- ruby/setup-ruby v1 composite
- actions/checkout v4 composite
- ruby/setup-ruby v1 composite
- rubygems/configure-rubygems-credentials v1.0.0 composite
- actions/checkout v4 composite
- ruby/setup-ruby v1 composite
- actions/checkout v4 composite
- ruby/setup-ruby v1 composite
Score: 29.912644291918323