Skip Menu |

This queue is for tickets about the XML-Simple CPAN distribution.

Report information
The Basics
Id: 34593
Status: rejected
Priority: 0/
Queue: XML-Simple

People
Owner: Nobody in particular
Requestors: sean [...] suchter.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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);
This is not a bug, you need to set the KeyAttr option to control how XMLout() unfolds a hash of hashes. However, if you want to round trip XML (read/modify/write) then XML::LibXML would be a much better choice of module than XML::Simple.
Subject: Re: [rt.cpan.org #34593] bug in XMLout with lists of items
Date: Tue, 01 Apr 2008 14:11:12 -0700
To: bug-XML-Simple [...] rt.cpan.org
From: Sean Suchter <sean [...] suchter.com>
Thanks for both helpful points! Sean Grant McLean via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=34593 > > > This is not a bug, you need to set the KeyAttr option to control how > XMLout() unfolds a hash of hashes. > > However, if you want to round trip XML (read/modify/write) then > XML::LibXML would be a much better choice of module than XML::Simple. >
You're welcome, but please don't reply to this email - evry reply re-opens the ticket in RT :-)