Introducing the xml-simple gem

Installation

gem install xml-simple

Example

require 'xmlsimple'

xml =<<XML
<config logdir="/var/log/foo/" debugfile="/tmp/foo.debug">
  <server name="sahara" osname="solaris" osversion="2.6">
    
10.0.0.101
    <address>10.0.1.101</address>
  </server>
  <server name="gobi" osname="irix" osversion="6.5">
    <address>10.0.0.102</address>
  </server>
  <server name="kalahari" osname="linux" osversion="2.0.34">
    <address>10.0.0.103</address>
    <address>10.0.1.103</address>
  </server>
</config>
XML

config = XmlSimple.xml_in(xml, { 'KeyAttr' => 'name'})

config.keys #=> ["logdir", "debugfile", :server] 
config['logdir'] #=> /var/log/foo

Resources

Tags:
Source:
1515hrs.txt
Published:
12-03-2014 15:15