Code Monkey home page Code Monkey logo

xmlhasher's Introduction

XmlHasher

Build Status Gem Version

Fast XML to Ruby Hash converter

Installation

XmlHasher is available through Rubygems and can be installed via:

$ gem install xmlhasher

or add it to your Gemfile like this:

gem 'xmlhasher'

Release Notes

See CHANGELOG.md

Usage

require 'xmlhasher'

# XmlHasher global configuration
#
# snakecase - convert all keys to snake case notation
# ignore_namespaces - remove XML namespaces
# string_keys - represent keys as Strings instead of Symbols
#
# here is default configuration
XmlHasher.configure do |config|
  config.snakecase = true
  config.ignore_namespaces = true
  config.string_keys = false
end

# alternatively, specify configuration options when instantiating a Parser
parser = XmlHasher::Parser.new(
  :snakecase => true,
  :ignore_namespaces => true,
  :string_keys => false
)

# by default, XmlHasher will convert all keys to symbols.  If you want all keys to be Strings, set :string_keys option to 'true'

# parse XML file
XmlHasher.parse(File.new('/path/to/my/file.xml'))

# parse XML string
XmlHasher.parse("<tag1><tag2>content</tag2></tag1>")
# => {:tag1=>{:tag2=>"content"}}

Benchmarks

How fast is it? Try it for yourself rake benchmark

Converting small xml from text to Hash:
                 user     system      total        real
activesupport(rexml)     0.196861   0.000692   0.197553 (  0.197756)
activesupport(libxml)    0.028840   0.000176   0.029016 (  0.029037)
activesupport(nokogiri)  0.044063   0.000516   0.044579 (  0.044618)
xmlsimple                0.225291   0.014291   0.239582 (  0.239756)
nori                     0.048385   0.000379   0.048764 (  0.048806)
xmlhasher                0.011791   0.000098   0.011889 (  0.011895)

Converting large xml from file to Hash:
                 user     system      total        real
activesupport(rexml)    25.891326   0.144542  26.035868 ( 26.052577)
activesupport(libxml)    3.911317   0.072332   3.983649 (  3.985904)
activesupport(nokogiri)  6.126251   0.061193   6.187444 (  6.191296)
xmlsimple               26.128386   0.120480  26.248866 ( 26.265013)
nori                     6.347459   0.028522   6.375981 (  6.380416)
xmlhasher                1.738668   0.027549   1.766217 (  1.767256)

Note: benchmarks were generated on a 2015 Macbook Pro using Ruby 2.5.1

Requirements

  • Ruby 2.0.0 or higher

Copyright

Copyright (c) 2013 Gene Drabkin. See LICENSE for details.

xmlhasher's People

Contributors

cloocher avatar stepozer avatar jqr avatar distroid avatar jonmidhir avatar realwudoka avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.