class XMLConverter
- XMLConverter
- Reference
- Object
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.crConstant Summary
-
VERSION =
{{ (`shards version /srv/crystaldoc.info/github-mamantoha-xml_converter-master/src`).chomp.stringify }}
Constructors
- .new(content : String, content_key : Symbol = :value, collapse : Bool = true)
- .new(xml : XML::Node, content_key : Symbol = :value, collapse : Bool = true)