A generic swappable back-end for XML parsing
Lots of Ruby libraries utilize XML parsing in some form, and everyone has their favorite XML library. In order to best support multiple XML parsers and libraries, multi_xml is a general-purpose swappable XML backend library. You use it like so:
require 'multi_xml' MultiXml.parser = :nokogiri MultiXml.parse('<tag>This is the contents</tag>') # parsed using Nokogiri MultiXml.parser = :rexml MultiXml.parser = MultiJson::Parser::Rexml # equivalent to previous line MultiXml.parse('<tag>This is the contents</tag>') # parsed using REXML
The parser setter takes either a symbol or a class (to allow for custom XML parsers) that responds to .parse at the class level.
MultiXML tries to have intelligent defaulting. That is, if you have any of the supported parsers already loaded, it will utilize them before attempting to load any. When loading, libraries are ordered by speed. First LibXML, then Nokogiri, then REXML.
MultiXML was inspired by MultiJSON.
Fork the project.
Commit your feature or bug fix.
Add tests for it. This is important so it doesn't break in the future.
Do not mess with gemspec, version, or history. (If you want to have your own version, that's fine, but please do so in a separate commit.)
Submit a pull request. Bonus points for topic branches.
Copyright © 2010 Erik Michaels-Ober. See LICENSE for details.