Home > xml_data_builder

xml_data_builder

Xml_data_builder is a project mainly written in Ruby, based on the MIT license.

XmlDataBuilder renders Ruby data structures as XML using Builder.

= xml_data_builder

XmlDataBuilder renders Ruby data structures as XML using Builder. It is designed to use the lowest common denominator between JSON and XML. When using arrays as input XmlDataBuilder uses the key of the outer hash as a grouping tag and wraps the values in singularized tags. Symbols and Strings are equivalent.

Usage is simple: You initialize XmlDataBuilder with ruby data structure and call #document:

puts XmlDataBuilder.new({}).document <?xml version="1.0" encoding="UTF-8"?>

puts XmlDataBuilder.new({:data => 1}).document <?xml version="1.0" encoding="UTF-8"?>

1

puts XmlDataBuilder.new({:outer => {:inner => 'data'}}).document <?xml version="1.0" encoding="UTF-8"?>

data

puts XmlDataBuilder.new({:outer => {:inner => 'data'}}, :indent => 0).document <?xml version="1.0" encoding="UTF-8"?>data

puts XmlDataBuilder.new({:numbers => [1, 2, 3]}).document <?xml version="1.0" encoding="UTF-8"?>

1 2 3

puts XmlDataBuilder.new({:numbers => [{:value => 1, :type => 'odd'}, {:value => 2, :type => 'even'}]}).document <?xml version="1.0" encoding="UTF-8"?>

odd 1 even 2

puts XmlDataBuilder.new({:verbatim => XmlDataBuilder::CDATA.new('eßcape thïs!')}).document <?xml version="1.0" encoding="UTF-8"?>

== Caveat

The root element has to be a Hash and at least every second level has to be a Hash. XML attributes are not supported.

== Installation

(sudo) gem install xml_data_builder

== Authors

Dr. Florian Odronitz ([email protected])

== Contact

For questions, contact the authors or [email protected]

== Copyright

Copyright (c) 2011 www.travel-iq.com. See LICENSE.txt for further details.