No commit activity in last 3 years
No release in over 3 years
XmlDataBuilder renders Ruby data structures as XML using Builder.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 3.0.0
~> 1.0.0
>= 0.5.0
~> 1.5.2
>= 2.3.0
 Project Readme

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"?>
<data>1</data>

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

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

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

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

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

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 (odo@mac.com)

Contact¶ ↑

For questions, contact the authors or developer@traveliq.net

Copyright © 2011 www.travel-iq.com. See LICENSE.txt for further details.