Class: FasterXmlSimple
- Inherits:
-
Object
- Object
- FasterXmlSimple
- Defined in:
- lib/faster_xml_simple.rb
Constant Summary collapse
- Version =
'0.5.0'
Class Method Summary collapse
-
.xml_in(string, options = {}) ⇒ Object
Take an string containing XML, and returns a hash representing that XML document.
Instance Method Summary collapse
-
#initialize(string, options) ⇒ FasterXmlSimple
constructor
:nodoc:.
-
#out ⇒ Object
:nodoc:.
Constructor Details
#initialize(string, options) ⇒ FasterXmlSimple
:nodoc:
57 58 59 60 |
# File 'lib/faster_xml_simple.rb', line 57 def initialize(string, ) #:nodoc: @doc = parse(string) @options = .merge end |
Class Method Details
.xml_in(string, options = {}) ⇒ Object
Take an string containing XML, and returns a hash representing that XML document. For example:
FasterXmlSimple.xml_in("<root><something>1</something></root>")
{"root"=>{"something"=>{"__content__"=>"1"}}}
Faster XML Simple is designed to be a drop in replacement for the xml_in functionality of xml-simple.rubyforge.org
The following options are supported:
-
contentkey
: The key to use for the content of text elements, defaults to ‘_content_’ -
forcearray
: The list of elements which should always be returned as arrays. Under normal circumstances single element arrays are inlined. -
suppressempty
: The value to return for empty elements, passtrue
to remove empty elements entirely. -
keeproot
: By default the hash returned has a single key with the name of the root element. If the name of the root element isn’t interesting to you, passfalse
. -
forcecontent
: By default a text element with no attributes, will be collapsed to just a string instead of a hash with a single key.Pass
true
to prevent this.
52 53 54 |
# File 'lib/faster_xml_simple.rb', line 52 def xml_in(string, ={}) new(string, ).out end |