[Chicago-talk] XML::Simple MXLout SuppressEmpty

Pete Krawczyk mongers at bsod.net
Thu Sep 28 10:58:53 PDT 2006

Subject: [Chicago-talk] XML::Simple MXLout SuppressEmpty
From: tiger peng <tigerpeng2001 at yahoo.com>
Date: Wed, 27 Sep 2006 12:59:50 -0700 (PDT)

}Is there simple way to avoid an empty hash being shown
}up as an empty element in XML with XML::Simple?

Not in the code itself, no.  It's assumed that if you have an empty 
reference, that you want the element there even if SuppressEmpty is on.
That's the point of XML::Simple - it's easy to use at the cost of making 
some things much more difficult than others.

If you really can't undef the reference, perhaps something like this will 
work for you:

use XML::Simple;
$hash = {};
print XMLout(
        category => {
                301994 => {
                        level => 2,
                        categroy => %$hash ? $hash : undef,
                        name => 'Furniture',
                        code => '301994'
}, SuppressEmpty=>1);

...which yields:

  <category name="Furniture" code="301994" level="2" />

-Pete K
Pete Krawczyk
  mongers at bsod dot net

More information about the Chicago-talk mailing list