in reply to Problems with XML::Dumper

I am starting to think that this is a bug in XML::Dumper. I followed the Perl debugger and found this oddity:
... main::(foo.pl:16): $config = $dumper->xml2pl($xml); DB<1> s XML::Dumper::xml2pl(.../XML/Dumper.pm:114): 114: my ($obj,$tree) = @_; DB<1> n XML::Dumper::xml2pl(.../XML/Dumper.pm:117): 117: my $TopItem = $tree->[1]; DB<1> n XML::Dumper::xml2pl(.../XML/Dumper.pm:118): 118: my $ref = &Undump($TopItem); DB<1> s XML::Dumper::Undump(.../XML/Dumper.pm:133): 133: my ($Tree) = shift; DB<1> n XML::Dumper::Undump(.../XML/Dumper.pm:134): 134: my $ref = undef; DB<1> n XML::Dumper::Undump(.../XML/Dumper.pm:135): 135: my $FoundScalar; DB<1> n XML::Dumper::Undump(.../XML/Dumper.pm:136): 136: my $i; DB<1> n XML::Dumper::Undump(.../XML/Dumper.pm:138): 138: for ($i = 1; $i < $#$Tree; $i+=2) { DB<1> n XML::Dumper::Undump(.../XML/Dumper.pm:178): 178: $ref = $FoundScalar unless defined($ref); DB<1> n XML::Dumper::Undump(/.../XML/Dumper.pm:180): 180: done: 181: return ($ref); DB<1> n XML::Dumper::xml2pl(/.../XML/Dumper.pm:120): 120: return($ref); DB<1> n main::(foo.pl:21): print Dumper $config;
The problems i see are on lines 117 and 138 of XML/Dumper.pm. The code expects the argument to xml2pl to be an array ref, when it is really a scalar. The result is the for loop not being entered, and eventually an undef is returned.

Additionally, the synopsis code is inconsistent (if not broken) and once i 'fixed' and ran it, it produced the same results as your script - undef for the return value of xml2pl.

Personally, i'd just use XML::Simple. There maybe more configuration options to worry about, but i also think that you should worry about those config options.

My apologies in advance to the author of XML::Dumper if i am wrong. If nobody tells me contrary within about 24 hours then i will notify the author.

Update - i received a /msg from blakem that stated the same conclusion.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: XML::Dumper
by theguvnor (Chaplain) on Jan 21, 2002 at 00:45 UTC
    ++jeffa.

    Thanks for confirming that I'm not the only one who can't make it work as advertised. I did briefly take a look at the .pm file to see if I could see anything obviously broken, but alas I was not. (But I also noticed the documentation was a little, er, inconsistent.) Hopefully the author will correct the problem, if it truly is a bug as jeffa's analysis points to.

    I have indeed fallen back to using XML::Simple. Thanks again.

(jeffa) 2Re: XML::Dumper
by jeffa (Bishop) on Dec 09, 2002 at 16:04 UTC
    ... nearly one year later ...

    I received an email from the new maintainer of XML::Dumper, Mike Wong, yesterday (2002-12-09). This bug has been fixed. :) Also, Mike has added more features such as handling circular references, the ability to read and write zlib-compressed XML, and some more (check out the Changes file that ships with the tar ball for more).

    Here is the output from theguvnor's code using XML::Dumper 0.59:
    [jeffa@trinity perl]$ ./foo.pl
    xml output: <perldata>
     <hashref memory_address="0x8108634">
      <item key="a key">a value</item>
      <item key="another key">another value</item>
     </hashref>
    </perldata>
    

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)