From: Maik Schmidt Date: 2003-04-29T04:43:20+09:00 Subject: [ANN] xml-simple 1.0.0 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:
10.0.0.101
10.0.1.101
10.0.0.102
10.0.0.103
10.0.1.103
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 You can download the current and all previous releases here: http://www.maik-schmidt.de/projects/xml-simple/dist/ The RAA site is: 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/ 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