class

XMLConverter

Inherits Reference < Object

Class to convert XML::Node or String object to Hash.

Simple example:

xml = <<-XML
  <person id="1">
    <firstname>Jane</firstname>
    <lastname>Doe</lastname>
    </person>
  XML

document = XML.parse(xml)
hash = XMLConverter.new(document, content_key: :_value, collapse: false).to_h
=> {"person" => {"id" => "1", "firstname" => {:_value => "Jane"}, "lastname" => {:_value => "Doe"}}}

Options:

content_key - name for text property for elements with attributes and text collapse - collapse elements that only contain text into a simple string property.

Constants

VERSION = {{ (`shards version /tmp/tmp.ECemhg/src/src`).chomp.stringify }}

Constructors

new(content : String, content_key : Symbol = :value, collapse : Bool = true)
Source
new(xml : XML::Node, content_key : Symbol = :value, collapse : Bool = true)
Source

Instance methods

content_key
Source
to_h
Source

Nested types