Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xmlhasher_with_attributes

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xmlhasher_with_attributes

  • 1.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

XmlHasher_with_attributes

Fast XML to Ruby Hash converter

This gem is a fork of a fork of XmlHasher (through pawelma). Regarding the original code, there's only one difference : it does not skip attributes if only content is provided. I did the work to publish the gem on rubygems.org with a different name to make it available.

Example:

XmlHasher.parse('<tag attribute="attr_val">content</tag>')

# In original xmlhasher above command will return following hash:
{
  tag: "content"
}

# With xmlhasher_with_attributes hash will be equal:
{
  tag: {
    attribute: "attr_val",
    value: "content"
  }
}

Installation

  • clone this repo
  • run
bundle install
rake install
  • require
require 'xmlhasher_with_attributes'

Usage

require 'xmlhasher_with_attributes'

# 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"}}

Requirements

  • Ruby 1.8.7 or higher

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

FAQs

Package last updated on 27 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc