class XMLConverter

Overview

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.

Defined in:

xml_converter.cr

Constant Summary

VERSION = {{ (`shards version /srv/crystaldoc.info/github-mamantoha-xml_converter-master/src`).chomp.stringify }}

Constructors

Instance Method Summary

Constructor Detail

def self.new(content : String, content_key : Symbol = :value, collapse : Bool = true) #

[View source]
def self.new(xml : XML::Node, content_key : Symbol = :value, collapse : Bool = true) #

[View source]

Instance Method Detail

def content_key : Symbol #

[View source]
def to_h #

[View source]