Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: alex [...] framexpeditions.com
Cc:
AdminCc:

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



Subject: XMLin keyattr=> default with name
Hi The subject is not clear but I hope my eample will be more. I'm not sure if you intent to do that, but it looks that XMLIn take the "name" sub element as a default attribute . If you have a look at the attached 99_nonunique.t, the third example produces a warning showing that. (see test output at the end) It does not produce the warning if keyattr=>{} or if the "name" sub element is renamed "hahaname" I think it was not the case with 2.14 (not sure) cheers Alex PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/99_nonunique....1/3 Warning: <item> element has non-unique value in 'name' key attribute: color at t/99_nonunique.t line 34 t/99_nonunique....ok All tests successful. Files=1, Tests=3, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.09 cusr 0.01 csys = 0.12 CPU) Result: PASS
Subject: 99_nonunique.t
use strict; use Test::More; use IO::File; use File::Spec; use XML::Simple; plan tests => 3; $^W = 1; my $xitems = q(<opt> <item hahaname="color">red</item> <item hahaname="color">green</item> </opt>); my $opt = XMLin($xitems); ok($opt); $xitems = q(<opt> <item name="color">red</item> <item name="color">green</item> </opt>); $opt = XMLin($xitems, keyattr => {}); ok($opt); $xitems = q(<opt> <item name="color">red</item> <item name="color">green</item> </opt>); $opt = XMLin($xitems); ok($opt);
It seems from your attached test file that the problem you are reporting is either: a) an attribute of 'name' is treated in a special way by default, or b) a warning is produced Neither of these is a bug. The special treatment of attributes called 'name', 'key' or 'id' has been an integral part of XML::Simple since before it was released on CPAN. It is documented in the section on the KeyAttr option. The introduction to the 'Options' section also highlights that you need to understand what KeyAttr does by default. The warning is produced in your example because XML::Simple encountered conflicting information. By not overriding the default value for KeyAttr you've indicated that the 'name' attribute will contain a unique key. However the XML document does not have unique values in the 'name' attributes. XML::Simple has no choice but to discard one of the elements. It generates a warning to let you know that it is doing that. If you are OK with data being silently discarded then you could turn off warnings. If you don't want data to be discarded then you must set KeyAttr. The 'Changes' file indicates that the warning message in this circumstance is new since version 1.18. In older versions, XML::Simple would silently discard elements without generating a warning. It is not good practise to call XMLin() without setting your preferred options. In particular, you should almost always select values for KeyAttr and ForceArray that match the data you are reading. This article provides more info: http://www.perlmonks.org/index.pl?node_id=218480
Subject: Re: [rt.cpan.org #45025] XMLin keyattr=> default with name
Date: Tue, 14 Apr 2009 14:45:35 +0200
To: bug-XML-Simple [...] rt.cpan.org
From: Alexandre Masselot <olav [...] genebio.com>
Hi Grant thanks for your reply So everything is under control;) I had just set this keyattr=>{} in XMLin to avoid being pollute by the warning in my tests and everything flies correctly. I just posted the bug report in case you had not seen the problem (but it looks like you master your ship) thank again for the work Akex On Apr 14, 2009, at 11:57 AM, Grant McLean via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=45025 > > > It seems from your attached test file that the problem you are > reporting > is either: > > a) an attribute of 'name' is treated in a special way by default, or > b) a warning is produced > > Neither of these is a bug. The special treatment of attributes called > 'name', 'key' or 'id' has been an integral part of XML::Simple since > before it was released on CPAN. It is documented in the section on > the > KeyAttr option. The introduction to the 'Options' section also > highlights that you need to understand what KeyAttr does by default. > > The warning is produced in your example because XML::Simple > encountered > conflicting information. By not overriding the default value for > KeyAttr you've indicated that the 'name' attribute will contain a > unique > key. However the XML document does not have unique values in the > 'name' > attributes. XML::Simple has no choice but to discard one of the > elements. It generates a warning to let you know that it is doing > that. > If you are OK with data being silently discarded then you could turn > off warnings. If you don't want data to be discarded then you must > set > KeyAttr. > > The 'Changes' file indicates that the warning message in this > circumstance is new since version 1.18. In older versions, > XML::Simple > would silently discard elements without generating a warning. > > It is not good practise to call XMLin() without setting your preferred > options. In particular, you should almost always select values for > KeyAttr and ForceArray that match the data you are reading. This > article provides more info: http://www.perlmonks.org/index.pl?node_id=218480
Alexandre Masselot, phD Development team leader Geneva BioInformatics http://www.genebio.com
Closing ticket