# \[ANN\] xml-simple 1.0.0

**URL:** <https://rubytalk.org/t/ann-xml-simple-1-0-0/5808>\
**Category:** ruby-talk\
**Created:** [28 April 2003 19:43 UTC](https://rubytalk.org/t/ann-xml-simple-1-0-0/5808 "2003-04-28T19:43:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maik\_Schmidt](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@Maik\_Schmidt](https://rubytalk.org/u/Maik_Schmidt)\
**Post date:** [28 April 2003 19:43 UTC](https://rubytalk.org/t/ann-xml-simple-1-0-0/5808/1 "2003-04-28T19:43:20Z")

</div>

Yo!

I have just released version 1.0.0 of xml-simple. This release offers  
a lot of new features and supports nearly all options of the current  
Perl version (XML::Simple 2.0.5 by Grant McLean). The only things  
missing are support for SAX2 and the so called ‘strict mode’.

Major changes:

- Added a cache that supports three caching models.
- All option names are case insensitive now and underscores  
are no longer significant, i.e.  
force\_array == ForceArray == forcearray == fOR\_\_CEArray
- The ‘ForceArray’ option supports regexes now.
- Added ‘Indent’ option that allows to specify an arbitrary  
string to be used for indentation by xml\_out.
- Added ‘GroupTags’ option, which allows to eliminate extra  
levels of indirection in Ruby data structures.
- Added ‘Variables’ option, which allows to expand variables  
in the XML to be expanded, when the file is read.
- Added ‘VarAttr’ option, which allows variables to be defined  
in the XML.
- Added ‘NormaliseSpace’ option, which controls how whitespace  
in text content is handles.
- Added ‘NoIndent’ option, which prints the whole XML output  
on one line.

You do not know, what xml-simple is at all? So, here we go:

XmlSimple offers an easy API to maintain XML (especially configuration  
files) and was heavily inspired by Grant McLean’s Perl module  
XML::Simple (Thank you very much, Grant, for such great code!!).

Example:

Say you have a file of configuration options called foo.xml containing  
this:

```
 <config logdir="/var/log/foo/" debugfile="/tmp/foo.debug">
   <server name="sahara" osname="solaris" osversion="2.6">
     <address>10.0.0.101</address>
     <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>

```

The following lines of code in foo:

```
 require 'xmlsimple'
 config = XmlSimple.xml_in('foo.xml', { 'KeyAttr' => 'name' })

```

will ‘slurp’ the configuration options into the Hash config (if no  
arguments are passed to xml\_in the name and location of the XML file  
will be inferred from name and location of the script). You can dump  
out the contents of the Hash using “p config”, which will produce  
something like this (formatting has been adjusted for brevity):

```
 {
   'logdir' => '/var/log/foo/',
   'debugfile' => '/tmp/foo.debug',
   'server' => {
     'sahara' => {
       'osversion' => '2.6',
       'osname' => 'solaris',
       'address' => ['10.0.0.101', '10.0.1.101']
     },
     'gobi' => {
       'osversion' => '6.5',
       'osname' => 'irix',
       'address' => ['10.0.0.102']
     },
     'kalahari' => {
       'osversion' => '2.0.34',
       'osname' => 'linux',
       'address' => ['10.0.0.103', '10.0.1.103']
     }
   }
 }

```

Your script could then access the name of the log directory like this:

```
 puts config['logdir']

```

Similarly, the second address on the server ‘kalahari’ could be  
referenced as:

```
 puts config['server']['kalahari']['address'][1]

```

What could be simpler? (Rhetorical).

You can find a short tutorial here:  
[http://www.maik-schmidt.de/projects/xml-simple/index.html](http://www.maik-schmidt.de/projects/xml-simple/index.html)

You can download the current and all previous releases here:  
[http://www.maik-schmidt.de/projects/xml-simple/dist/](http://www.maik-schmidt.de/projects/xml-simple/dist/)

The RAA site is:  
[http://www.ruby-lang.org/raa/list.rhtml?name=xml-simple](http://www.ruby-lang.org/raa/list.rhtml?name=xml-simple)

You can find the original Perl version here:  
[http://www.cpan.org/modules/by-module/XML/GRANTM/](http://www.cpan.org/modules/by-module/XML/GRANTM/)

Currently, I am adding all features of the Perl version, that did  
not find their way into this release. Additionally, I will integrate  
XmlSimple into XmlConfigFile.

Cheers,

> **···**
>
> –  
> Maik Schmidt  
> [mailto:contact@maik-schmidt.de](mailto:contact@maik-schmidt.de)

---

<div class="post-metadata">

**Author:** ![Michael\_Vondung1](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@Michael\_Vondung1](https://rubytalk.org/u/Michael_Vondung1)\
**Post date:** [29 April 2003 07:28 UTC](https://rubytalk.org/t/ann-xml-simple-1-0-0/5808/2 "2003-04-29T07:28:46Z")

</div>

Thanks! That’s exactly what I was looking for. Awesome. 🙂

-M.

> **···**
>
> On Mon, 28 Apr 2003 21:23:03 +0200, Maik Schmidt [contact@maik-schmidt.de](mailto:contact@maik-schmidt.de) wrote:
> 
> > I have just released version 1.0.0 of xml-simple.
