[lug] Advice on writing a config file (probably XML)

Michael J. Hammel mjhammel at graphics-muse.org
Sun Dec 14 09:37:26 MST 2003

On Sat, 2003-12-13 at 19:49, Jon Bowman wrote:
> Anyway I assume XML is probably the cleanest way to write a
> config
> file. Never having done this before or used XML does anyone have
> any
> recommendation / pointers to get me started. The application is
> written
> in C so are there any libraries / functions I can make use of ?

I went through this same issue this past summer when adding XML
configuration files to some GIMP plugins.  It was a little confusing at
first - its all about trees, root nodes and children.

Look at libxml - http://xmlsoft.org/

You can use this for C apps and there are bindings for other languages
too (I'm about to look at it for parsing RSS files with PHP - if anyknow
knows of any ready-made PHP addons for this, let me know).  For simple
cases you might just parse with this library and store stuff in glib
link lists for easier handling.  

There are some reasonably decent examples
(http://xmlsoft.org/examples/index.html) online.  You can look at the
tree1.c example (http://xmlsoft.org/examples/tree1.c) for a simple "read
file, run through the element tree and print each node" scenario.

I wrote a little library on top of libXML to handle my config file
stuff.  It's not that little, though.  XML almost seems like overkill
for really simple config files.  For more complex data, though, it makes
Michael J. Hammel                               The Graphics Muse 
mjhammel at graphics-muse.org                      http://www.graphics-muse.com
Share your knowledge. It's a way to achieve immortality.
  --  Credited to the Dalai Lama.

More information about the LUG mailing list