metaperl has asked for the wisdom of the Perl Monks concerning the following question:

In the following XML::Simple program, XMLin produces an empty hashref for the key groups.

I'm curious (after searching the FAQ and this site) how to force such an element to an empty string:

use XML::Simple; my $xml=<<'EOXML'; <config logdir="/var/log/foo/" debugfile="/tmp/foo.debug"> <groups></groups> <age>18</age> <weight>220</weight> </config> EOXML my $xs = XML::Simple->new; my $ref = $xs->XMLin($xml); use Data::Dumper; warn Dumper($ref);

transcript

[tbrannon@devel tmp]$ perl xml-simple.pl $VAR1 = { 'debugfile' => '/tmp/foo.debug', 'weight' => '220', 'groups' => {}, #### <---- want empty string here! 'age' => '18', 'logdir' => '/var/log/foo/' };

Replies are listed 'Best First'.
Re: XML::Simple - forcing empty elements to empty string?
by ikegami (Patriarch) on Jun 16, 2009 at 13:20 UTC
    Use option ForceContent => 1 and add ->{content} everywhere you want the text of an element.
Re: XML::Simple - forcing empty elements to empty string?
by Anonymous Monk on Jun 16, 2009 at 13:27 UTC