0.0
No commit activity in last 3 years
No release in over 3 years
This a fork from Daniel Harrington's Nori with nokogiri updated to 1.6
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.4.0
~> 10.0
~> 2.12
 Project Readme

Nori

Build Status Gem Version Code Climate Coverage Status

Really simple XML parsing ripped from Crack which ripped it from Merb.
Nori was created to bypass the stale development of Crack, improve its XML parser
and fix certain issues.

parser = Nori.new
parser.parse("<tag>This is the contents</tag>")
# => { 'tag' => 'This is the contents' }

Nori supports pluggable parsers and ships with both REXML and Nokogiri implementations.
It defaults to Nokogiri since v2.0.0, but you can change it to use REXML via:

Nori.new(:parser => :rexml)  # or :nokogiri

Make sure Nokogiri is in your LOAD_PATH when parsing XML, because Nori tries to load it
when it's needed.

Typecasting

Besides regular typecasting, Nori features somewhat "advanced" typecasting:

  • "true" and "false" String values are converted to TrueClass and FalseClass.
  • String values matching xs:time, xs:date and xs:dateTime are converted to Time, Date and DateTime objects.

You can disable this feature via:

Nori.new(:advanced_typecasting => false)

Namespaces

Nori can strip the namespaces from your XML tags. This feature might raise
problems and is therefore disabled by default. Enable it via:

Nori.new(:strip_namespaces => true)

XML tags -> Hash keys

Nori lets you specify a custom formula to convert XML tags to Hash keys.
Let me give you an example:

parser = Nori.new(:convert_tags_to => lambda { |tag| tag.snakecase.to_sym })

xml = '<userResponse><accountStatus>active</accountStatus></userResponse>'
parser.parse(xml)  # => { :user_response => { :account_status => "active" }