# \[ANN\] xml-simple 0.6.0

**URL:** <https://rubytalk.org/t/ann-xml-simple-0-6-0/5424>\
**Category:** ruby-talk\
**Created:** [30 March 2003 19:10 UTC](https://rubytalk.org/t/ann-xml-simple-0-6-0/5424 "2003-03-30T19:10:15Z")\
**Posts on this page:** 7\
**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:** [30 March 2003 19:10 UTC](https://rubytalk.org/t/ann-xml-simple-0-6-0/5424/1 "2003-03-30T19:10:15Z")

</div>

Yo!

I have just released a _new_ Ruby library called xml-simple. It offers  
an easy API to maintain XML (especially configuration files) and was  
heavily inspried 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:

```
         require 'xmlsimple'
         config = XmlSimple.xml_in('foo.xml', { 'key_attr' => '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:** ![Meinrad\_Recheis](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Meinrad\_Recheis](https://rubytalk.org/u/Meinrad_Recheis)\
**Post date:** [30 March 2003 21:51 UTC](https://rubytalk.org/t/ann-xml-simple-0-6-0/5424/2 "2003-03-30T21:51:08Z")

</div>

hi

i find it somewhat strange, that the “name”-attribute is a hash  
containing the rest of the attributes as also the subnodes of this node.  
do you take the first attribute to identify a node?

also it could possibly save a lot of finger-typing if you encapsulated  
the “not so cool” hash in an object that supports XPath

puts config[‘server’][‘kalahari’][‘address’][1] # vs.

puts xml.get(‘/config/server/kalahari/address’)[1] # or  
puts xml.get(‘/config/server(name=kalahari)/address’)[1] # best

just my suggestions.

- Meinrad

Maik Schmidt wrote:

> **···**
>
> > Yo!
> > 
> > I have just released a _new_ Ruby library called xml-simple. It offers  
> > an easy API to maintain XML (especially configuration files) and was  
> > heavily inspried 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:
> > 
> > ```
> > require 'xmlsimple'
> > config = XmlSimple.xml_in('foo.xml', { 'key_attr' => '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,

---

<div class="post-metadata">

**Author:** ![Josef\_Jupp\_SCHUGT](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@Josef\_Jupp\_SCHUGT](https://rubytalk.org/u/Josef_Jupp_SCHUGT)\
**Post date:** [31 March 2003 13:32 UTC](https://rubytalk.org/t/ann-xml-simple-0-6-0/5424/3 "2003-03-31T13:32:51Z")

</div>

Hi!

- Maik Schmidt [contact@maik-schmidt.de](mailto:contact@maik-schmidt.de); 2003-03-30, 22:28 UTC:

> Similarly, the second address on the server ‘kalahari’ could be  
> referenced as:
> 
> ```
> puts config['server']['kalahari']['address'][1]
> 
> ```
> 
> What could be simpler? (Rhetorical).

That question is not as rhetorical as it may seem:

```
http://raa.ruby-lang.org/list.rhtml?name=xml-configfile

```

Josef ‘Jupp’ Schugt [http://jupp.tux.nu](http://jupp.tux.nu) jupp(AT)gmx(DOT)de

> **···**
>
> –  
> “Mankind must put an end to war before war puts an end to mankind.”  
> – John F. Kennedy

---

<div class="post-metadata">

**Author:** ![Han\_Holl2](https://avatars.discourse-cdn.com/v4/letter/h/ecc23a/32.png) [@Han\_Holl2](https://rubytalk.org/u/Han_Holl2)\
**Post date:** [31 March 2003 18:51 UTC](https://rubytalk.org/t/ann-xml-simple-0-6-0/5424/4 "2003-03-31T18:51:02Z")

</div>

Maik Schmidt wrote:

> Yo!
> 
> I have just released a _new_ Ruby library called xml-simple. It offers  
> an easy API to maintain XML (especially configuration files) and was  
> heavily inspried by Grant McLean’s Perl module XML::Simple (Thank you  
> very much, Grant, for such great code!!).  
> Hi,

I downloaded the zip file (twice) and get, on  
unzip -l tmp/xml-simple\_0.6.0.zip :

Archive: /tmp/xml-simple\_0.6.0.zip  
End-of-central-directory signature not found. Either this file is not  
a zipfile, or it constitutes one disk of a multi-part archive. In the  
latter case the central directory and zipfile comment will be found on  
the last disk(s) of this archive.  
unzip: cannot find zipfile directory in one of /tmp/xml-simple\_0.6.0.zip or  
/tmp/xml-simple\_0.6.0.zip.zip, and cannot find  
/tmp/xml-simple\_0.6.0.zip.ZIP, period.

This is unzip from unzip-5.50 from [www.info-zip.org](http://www.info-zip.org) on Linux.

Any ideas ?

Cheers,

Han

---

<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:** [30 March 2003 22:51 UTC](https://rubytalk.org/t/ann-xml-simple-0-6-0/5424/5 "2003-03-30T22:51:43Z")

</div>

Meinrad Recheis wrote:

> **···**
>
> > i find it somewhat strange, that the “name”-attribute is a hash  
> > containing the rest of the attributes as also the subnodes of this node.  
> > do you take the first attribute to identify a node?
> > 
> > > No, you can control the structure by using the option ‘key\_attr’ as  
> > > described extensively in the tutorial. E.g., you can disable the  
> > > folding completely by setting ‘key\_attr’ = (the default). Maybe  
> > > you want to take another look at the manual and give ‘key\_attr’ a  
> > > chance 😉
> 
> > also it could possibly save a lot of finger-typing if you encapsulated  
> > the “not so cool” hash in an object that supports XPath
> > 
> > puts config[‘server’][‘kalahari’][‘address’][1] # vs.
> > 
> > puts xml.get(‘/config/server/kalahari/address’)[1] # or  
> > puts xml.get(‘/config/server(name=kalahari)/address’)[1] # best
> > 
> > > That is really funny, because what you suggest here can be found  
> > > in another Ruby library I wrote: XmlConfigFile. Get it from RAA:  
> > > [http://raa.ruby-lang.org/list.rhtml?name=xml-configfile](http://raa.ruby-lang.org/list.rhtml?name=xml-configfile)  
> > > It allows you to access configuration parameters in an XML file  
> > > using XPath. But many people asked for an easy way to completely  
> > > serialize an XML document and so I decided to port XML::Simple to  
> > > Ruby. I want to combine these two libraries in the next weeks, i.e.  
> > > XmlConfigFile will use XmlSimple for serializing purposes.
> 
> > just my suggestions.
> > 
> > > Thank you! They are always very welcome!

---

<div class="post-metadata">

**Author:** ![Mauricio\_Fernndez](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mauricio\_Fernndez](https://rubytalk.org/u/Mauricio_Fernndez)\
**Post date:** [31 March 2003 15:53 UTC](https://rubytalk.org/t/ann-xml-simple-0-6-0/5424/6 "2003-03-31T15:53:49Z")

</div>

The author must find this really flattering 🙂

Project name: xml-configfile  
Short description: Easy handling of XML configuration files.  
Owner: Maik Schmidt

Project name: xml-simple  
Short description: Easy API to maintain XML  
Owner: Maik Schmidt

> **···**
>
> On Mon, Mar 31, 2003 at 10:32:51PM +0900, Josef ‘Jupp’ Schugt wrote:
> 
> > Hi!
> > 
> > - Maik Schmidt [contact@maik-schmidt.de](mailto:contact@maik-schmidt.de); 2003-03-30, 22:28 UTC:
> > 
> > > Similarly, the second address on the server ‘kalahari’ could be  
> > > referenced as:
> > > 
> > > ```
> > > puts config['server']['kalahari']['address'][1]
> > > 
> > > ```
> > > 
> > > What could be simpler? (Rhetorical).
> > 
> > That question is not as rhetorical as it may seem:
> > 
> > ```
> > http://raa.ruby-lang.org/list.rhtml?name=xml-configfile
> > 
> > ```
> 
> –  
> \_ \_
> 
> > > \_\_ \_\_ _| |_ \_\_\_ \_ \_\_ \_\_\_ \_\_ \_ \_ \_\_  
> > > '\_ \ / _`| __/__ | '_` \_ \ / ` | ’ \   
> > > ) | (| | |_\_\_ \ | | | | | (_| | | | |  
> > > .\_\_/ \_,_|\ __|__ /| |_| |_|\__,_|_| |\_|  
> > > Running Debian GNU/Linux Sid (unstable)  
> > > batsman dot geo at yahoo dot com
> 
> People disagree with me. I just ignore them.  
> – Linus Torvalds, regarding the use of C++ for the Linux kernel

---

<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:** [31 March 2003 19:57 UTC](https://rubytalk.org/t/ann-xml-simple-0-6-0/5424/7 "2003-03-31T19:57:48Z")

</div>

Han Holl wrote:

> I downloaded the zip file (twice) and get, on  
> unzip -l tmp/xml-simple\_0.6.0.zip :
> 
> Archive: /tmp/xml-simple\_0.6.0.zip  
> End-of-central-directory signature not found. Either this file is not  
> a zipfile, or it constitutes one disk of a multi-part archive. In the  
> latter case the central directory and zipfile comment will be found on  
> the last disk(s) of this archive.  
> unzip: cannot find zipfile directory in one of  
> /tmp/xml-simple\_0.6.0.zip or  
> /tmp/xml-simple\_0.6.0.zip.zip, and cannot find  
> /tmp/xml-simple\_0.6.0.zip.ZIP, period.
> 
> This is unzip from unzip-5.50 from [www.info-zip.org](http://www.info-zip.org) on Linux.
> 
> Any ideas ?

I’m sorry! For a reason that is still a mystery to me, my FTP  
client assumed the zip archive to be an ASCII file and turned it  
into a pile of “byte rubbish” while uploading it. Usually I download  
the file again from my web site and check, if everything is fine.  
This time I forgot it! Damn!!

I have forced my FTP client to use binary mode now and if you try to  
download it again, everything should work fine!

Sorry for the inconvenience!

Cheers,
