Module MultiXml
In: lib/multi_xml/version.rb
lib/multi_xml/parsers/ox.rb
lib/multi_xml/parsers/nokogiri.rb
lib/multi_xml/parsers/libxml2_parser.rb
lib/multi_xml/parsers/libxml.rb
lib/multi_xml/parsers/rexml.rb
lib/multi_xml.rb

Each MultiXml parser is expected to parse an XML document into a Hash. The conversion rules are:

  • Each document starts out as an empty Hash.
  • Reading an element created an entry in the parent Hash that has a key of the element name and a value of a Hash with attributes as key value pairs. Children are added as described by this rule.
  • Text and CDATE is stored in the parent element Hash with a key of ‘content’ and a value of the text itself.
  • If a key already exists in the Hash then the value associated with the key is converted to an Array with the old and new value in it.
  • Other elements such as the xml prolog, doctype, and comments are ignored.

Methods

Classes and Modules

Module MultiXml::Parsers
Class MultiXml::ParseError

Constants

VERSION = "0.4.1"
REQUIREMENT_MAP = [ ['libxml', :libxml], ['nokogiri', :nokogiri], ['ox', :ox], ['rexml/document', :rexml]
CONTENT_ROOT = '__content__'.freeze unless defined?(CONTENT_ROOT)
PARSING = { 'symbol' => Proc.new{|symbol| symbol.to_sym}, 'date' => Proc.new{|date| Date.parse(date)}, 'datetime' => Proc.new{|time| Time.parse(time).utc rescue DateTime.parse(time).utc}, 'integer' => Proc.new{|integer| integer.to_i}, 'float' => Proc.new{|float| float.to_f}, 'decimal' => Proc.new{|number| BigDecimal(number)}, 'boolean' => Proc.new{|boolean| !%w(0 false).include?(boolean.strip)}, 'string' => Proc.new{|string| string.to_s}, 'yaml' => Proc.new{|yaml| YAML::load(yaml) rescue yaml}, 'base64Binary' => Proc.new{|binary| binary.unpack('m').first}, 'binary' => Proc.new{|binary, entity| parse_binary(binary, entity)}, 'file' => Proc.new{|file, entity| parse_file(file, entity)}

Public Class methods

The default parser based on what you currently have loaded and installed. First checks to see if any parsers are already loaded, then checks to see which are installed if none are loaded.

Parse an XML string or IO into Ruby.

Options

:symbolize_keys :If true, will use symbols instead of strings for the keys.

Get the current parser class.

Set the XML parser utilizing a symbol, string, or class. Supported by default are:

  • :libxml
  • :nokogiri
  • :ox
  • :rexml

[Validate]