# Configuration file parser like Config::General for perl

**URL:** <https://www.ruby-forum.com/t/configuration-file-parser-like-config-general-for-perl/113772>\
**Category:** Ruby\
**Created:** [September 4, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/configuration-file-parser-like-config-general-for-perl/113772 "2007-09-04T20:35:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tammo\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea5d25/32.png) [@Tammo\_T](https://www.ruby-forum.com/u/Tammo_T)\
**Post date:** [September 4, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/configuration-file-parser-like-config-general-for-perl/113772/1 "2007-09-04T20:35:44Z")

</div>

Hello,  
I have the problem, that in a project I am working in the configuration  
files are in a apache config file like format. This is a mixture of  
XML-Format and normal config format like  
  
name example  
use “for test”

The normal used language is perl, where the format, with some  
extensions, is  
supported by the Config::General Package.  
Is the something similar existing for Ruby? I have already searched in  
rubyforge, but I could not find something fitting. Somehow xmldigest or  
digestr seems partly to fit, but I am unsure if they support the whole  
range of the config-file. Or are there some settings existing for the  
xml-libraries like rexml to support this uncomliant kind of XML?

Best regards,  
Tammo

---

<div class="post-metadata">

**Author:** ![Tammo\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea5d25/32.png) [@Tammo\_T](https://www.ruby-forum.com/u/Tammo_T)\
**Post date:** [September 4, 2007, 8:57pm UTC](https://www.ruby-forum.com/t/configuration-file-parser-like-config-general-for-perl/113772/2 "2007-09-04T20:57:50Z")

</div>

On Sep 4, 11:35 am, Tammo T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> supported by the Config::General Package.  
> Is the something similar existing for Ruby? I have already searched in  
> rubyforge, but I could not find something fitting. Somehow xmldigest or  
> digestr seems partly to fit, but I am unsure if they support the whole  
> range of the config-file. Or are there some settings existing for the  
> xml-libraries like rexml to support this uncomliant kind of XML?

I know nothing of the sort. However, if should be pretty easy to use  
REXML to loop through the XML elements and apply a parser to each  
sections text.

T.

---

<div class="post-metadata">

**Author:** ![Tammo\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea5d25/32.png) [@Tammo\_T](https://www.ruby-forum.com/u/Tammo_T)\
**Post date:** [September 4, 2007, 10:06pm UTC](https://www.ruby-forum.com/t/configuration-file-parser-like-config-general-for-perl/113772/3 "2007-09-04T22:06:24Z")

</div>

Trans wrote:

> > 
> 
> REXML to loop through the XML elements and apply a parser to each  
> sections text.
> 
> T.

## Thanks for your answer. But I am not sure if that works without workaround. The Problem is, that the apache config file format allowas also things like:

version 1.0

root “not existing”

 driver X11 name test perl 5.8.2 ruby 1.8.6
* * *

I should mention that this is a meaningless example. The important point  
is,  
that you do not have proper xpaths and root-nodes. I have tried it once  
with rexml and it was somehow complaining (I have to look, but it was  
something with a line in rexml with \<\<)

What I can try is to surround it by a master-node before read-in but  
that is  
a hack and I am not sure if it will work. Anyway I will try.

Regards,  
Tammo

---

<div class="post-metadata">

**Author:** ![Tammo\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea5d25/32.png) [@Tammo\_T](https://www.ruby-forum.com/u/Tammo_T)\
**Post date:** [September 5, 2007, 12:41pm UTC](https://www.ruby-forum.com/t/configuration-file-parser-like-config-general-for-perl/113772/4 "2007-09-05T12:41:01Z")

</div>

On Sep 4, 1:21 pm, Tammo T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > 
> > 
> > REXML to loop through the XML elements and apply a parser to each
> 
> * * *
> 
> I should mention that this is a meaningless example. The important point is,  
> that you do not have proper xpaths and root-nodes. I have tried it once  
> with rexml and it was somehow complaining (I have to look, but it was  
> something with a line in rexml with \<\<)
> 
> What I can try is to surround it by a master-node before read-in but that is  
> a hack and I am not sure if it will work. Anyway I will try.

If they are only using Xml to do dead simple … braketing,  
then you could write a parser for that too. As long as there is no  
nesting of identically named nodes, it is very simple parsing and  
Regexp’s can be used to do it.

Just a thought.  
T.
