Then I guess I have to tweak XML::Simple :-)
Here is a patch that adds another option for suppressempty that instructs XML::Simple to keep the whitespace IFF there are no subtags.

--- XML/Simple.pm~ Tue Oct 22 20:05:02 2002 +++ XML/Simple.pm Wed May 19 16:22:56 2004 @@ -690,6 +690,7 @@ # Add any nested elements + my $keepspaces = (scalar(@_) == 2 and $self->{opt}->{suppressempty} + eq '0'); # only if there are no subtags my($key, $val); while(@_) { $key = shift; @@ -700,7 +701,7 @@ next if(!defined($val) and $self->{opt}->{suppressempty}); } elsif($key eq '0') { - next if($val =~ m{^\s*$}s); # Skip all whitespace content + next if (!$keepspaces and $val =~ m{^\s*$}s); # Skip all white +space content, if(!%$attr and !@_) { # Short circuit text in tag with n +o attr return($self->{opt}->{forcecontent} ? { $self->{opt}->{contentkey} => $val } : $val @@ -1426,7 +1427,7 @@ When used with C<XMLin()>, any attributes in the XML will be ignored. -=item suppressempty => 1 | '' | undef (B<in>) +=item suppressempty => 1 | '' | undef | 0 (B<in>) This option controls what C<XMLin()> should do with empty elements (n +o attributes and no content). The default behaviour is to represent th +em as @@ -1433,8 +1434,10 @@ empty hashes. Setting this option to a true value (eg: 1) will cause + empty elements to be skipped altogether. Setting the option to 'undef' or +the empty string will cause empty elements to be represented as the undefined v +alue or -the empty string respectively. The latter two alternatives are a lit +tle -easier to test for in your code than a hash with no keys. +the empty string respectively. The latter two alternatives are a lit +tle easier +to test for in your code than a hash with no keys. Setting the optio +n to 0 +will cause elements containing only whitespace to stay intact in the +resulting +structure. =item cache => [ cache scheme(s) ] (B<in>)

That is if you set suppressempty=>0 then

<tag> </tag>
will produce
$data = { tag => ' ', }
, while
<tag> <subtag>hello</subtag> <other>world</other> </tag> <code> will produce <code> $data = { tag => { subtag => 'hello', other => 'world', } }

I'll submit the patch to Grant McLean in a few days if there are no problems with it.

Jenda
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Edit by castaway: Closed small tag in signature


In reply to Re: Re: Re: Re: XML::Simple and &lt;tag&gt &lt;/tag&gt; by Jenda
in thread XML::Simple and &lt;tag&gt &lt;/tag&gt; by Jenda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.