--- 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 |