Subject: | bug in XMLout with lists of items |
Date: | Tue, 01 Apr 2008 08:00:11 -0700 |
To: | bug-XML-Simple [...] rt.cpan.org |
From: | Sean Suchter <sean [...] suchter.com> |
Hi, I think I've found an easily reproducible bug in XMLout. If it
matters, uname -a shows:
Darwin bigmac.ssuchter.com 8.11.0 Darwin Kernel Version 8.11.0: Wed Oct
10 18:26:00 PDT 2007; root:xnu-792.24.17~1/RELEASE_PPC Power Macintosh
powerpc
This is perl, v5.8.6 built for darwin-thread-multi-2level
(with 4 registered patches, see perl -V for more detail)
# $Id: Simple.pm,v 1.40 2007/08/15 10:36:48 grantm Exp $
(from cpan)
The bug is reproducible with the below self-contained script. The
problem (I think) is that the input uses list-ish formatting, but the
XMLout routine collapses the details and link sub-items into attributes
of the item container, thus not quite producing the right XML out. If it
produced <item>...</item> like the input it would be fine. You can see
the problem in 2 ways:
1. XMLin properly emits a warning on the second parse
2. The second Dumper output clearly shows data loss
Thanks,
Sean
#!/usr/local/bin/perl -w
use strict;
use XML::Simple;
my $inputXML = "<container>
<details>foobar</details>
<item>
<details>
<d>firstdetail</d>
<e>seconddetail</e>
</details>
<link>
<url>http://www.yahoo.com/</url>
</link>
</item>
<item>
<details>
<d>2firstdetail</d>
<e>2seconddetail</e>
</details>
<link>
<url>http://search.yahoo.com/</url>
</link>
</item>
</container>";
my $xml = new XML::Simple;
my $data = $xml->XMLin($inputXML);
use Data::Dumper;
print Dumper($data);
my $intermediateXML = $xml->XMLout($data);
print $intermediateXML;
my $data2 = $xml->XMLin($intermediateXML);
print Dumper($data2);