Jenda has asked for the wisdom of the Perl Monks concerning the following question:
Is there any way to force XML::Simple to keep the spaces?
printsuse strict; use XML::Simple; use Data::Dumper; my $Parser = new XML::Simple( forcearray => [qw(LOCALE)], suppressempty => '', ); my $data = $Parser->XMLin(<<'*END*'); <tag> <subtag> </subtag> <othertag> ahoj </othertag> </tag> *END* print Dumper($data);
I need the $data->{subtag} eq ' ', not ''.$VAR1 = { 'othertag' => ' ahoj ', 'subtag' => '' };
I tried to encode the space as  , but that did not make any difference. I also tried all other values of the suppressempty option, but that did not help. P.S.: It's quite possible there will be several spaces in the tag, I need them all!
Update: I patched XML::Simple and added a new value for the suppressempty option that does what I need.
Update:Actually the patch is incomplete, I need to get empty strings, not undefs for the completely empty tags. So I've added another option. ' ' = keep the spaces, return '' for empty tags vs. '0' = keep the spaces, return undef for empty tags. I'll post the updated patch later. If anyone has a better idea what values to use, I'm all ears :-)
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: XML::Simple and <tag> </tag>
by Aragorn (Curate) on May 18, 2004 at 18:26 UTC | |
by gmpassos (Priest) on May 18, 2004 at 20:12 UTC | |
by Aragorn (Curate) on May 18, 2004 at 21:15 UTC | |
by BigLug (Chaplain) on May 19, 2004 at 12:38 UTC | |
by Jenda (Abbot) on May 19, 2004 at 14:46 UTC | |
Re: XML::Simple and <tag> </tag>
by Ryszard (Priest) on May 19, 2004 at 10:25 UTC |