Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (54 sloc) 2.02 KB


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{}).document
<?xml version="1.0" encoding="UTF-8"?>

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

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

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

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

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

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


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


(sudo) gem install xml_data_builder


Dr. Florian Odronitz (


For questions, contact the authors or


Copyright © 2011 See LICENSE.txt for further details.