Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: DAVEWOOD [...] cpan.org
Cc:
AdminCc:

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



Subject: dataloss with non-unique id attr
As you can see in the attached example the first item is "overriden" without any warning. I am not saying that XML::LibXML::Simple is wrong here, but I dont know enough about XML to figure out where the error lies. #!/usr/bin/env perl use 5.018; use warnings; use XML::LibXML::Simple qw/ XMLin /; sub xml2pl { my ( $xml ) = @_; my %config = ( KeepRoot => 1, ForceArray => 0, KeyAttr => undef, ); my $xs = XML::LibXML::Simple->new(%config); my $pl = $xs->XMLin($xml); return $pl; } my $xml = <<"HERE"; <result> <item id="id-123">a</item> <item id="id-123">b</item> </result> HERE my $pl = xml2pl($xml); use Data::Dumper; say Dumper($pl); $VAR1 = { 'result' => { 'item' => { 'id-123' => { 'content' => 'b' } } } };
On 2016-04-27 08:20:37, DAVEWOOD wrote: Show quoted text
> As you can see in the attached example the first item is "overriden" > without any warning. I am not saying that XML::LibXML::Simple is wrong > here, but I dont know enough about XML to figure out where the error > lies. > > #!/usr/bin/env perl > use 5.018; > use warnings; > use XML::LibXML::Simple qw/ XMLin /; > > sub xml2pl { > my ( $xml ) = @_; > > my %config = ( > KeepRoot => 1, > ForceArray => 0, > KeyAttr => undef, > ); > my $xs = XML::LibXML::Simple->new(%config); > my $pl = $xs->XMLin($xml); > return $pl; > } > > my $xml = <<"HERE"; > <result> > <item id="id-123">a</item> > <item id="id-123">b</item> > </result> > HERE > > my $pl = xml2pl($xml); > use Data::Dumper; > say Dumper($pl); > > > $VAR1 = { > 'result' => { > 'item' => { > 'id-123' => { > 'content' => 'b' > } > } > } > };
A warning is issued if perl is executed with the -w switch: $ perl -w test.pl <item> element has non-unique value in 'id' key attribute: id-123 at /usr/perl5.22.1sp/lib/site_perl/5.22.1/XML/LibXML/Simple.pm line 463. $VAR1 = { 'result' => { 'item' => { 'id-123' => { 'content' => 'b' } } } }; Anyway, I wonder if this module should be marked as "discouraged". After all it's a clone if XML::Simple, and that module has in the meantime this notice: https://metacpan.org/pod/XML::Simple#STATUS-OF-THIS-MODULE
On Thu Apr 28 02:34:52 2016, SREZIC wrote: Show quoted text
> On 2016-04-27 08:20:37, DAVEWOOD wrote:
> > As you can see in the attached example the first item is "overriden" > > without any warning. I am not saying that XML::LibXML::Simple is > > wrong > > here, but I dont know enough about XML to figure out where the error > > lies. > > > > #!/usr/bin/env perl > > use 5.018; > > use warnings; > > use XML::LibXML::Simple qw/ XMLin /; > > > > sub xml2pl { > > my ( $xml ) = @_; > > > > my %config = ( > > KeepRoot => 1, > > ForceArray => 0, > > KeyAttr => undef, > > ); > > my $xs = XML::LibXML::Simple->new(%config); > > my $pl = $xs->XMLin($xml); > > return $pl; > > } > > > > my $xml = <<"HERE"; > > <result> > > <item id="id-123">a</item> > > <item id="id-123">b</item> > > </result> > > HERE > > > > my $pl = xml2pl($xml); > > use Data::Dumper; > > say Dumper($pl); > > > > > > $VAR1 = { > > 'result' => { > > 'item' => { > > 'id-123' => { > > 'content' => 'b' > > } > > } > > } > > };
> > A warning is issued if perl is executed with the -w switch: > > $ perl -w test.pl > <item> element has non-unique value in 'id' key attribute: id-123 at > /usr/perl5.22.1sp/lib/site_perl/5.22.1/XML/LibXML/Simple.pm line 463. > $VAR1 = { > 'result' => { > 'item' => { > 'id-123' => { > 'content' => 'b' > } > } > } > }; > > Anyway, I wonder if this module should be marked as "discouraged". > After all it's a clone if XML::Simple, and that module has in the > meantime this notice: > https://metacpan.org/pod/XML::Simple#STATUS-OF-THIS-MODULE
I am using XML::LibXML::Simple, this module is not deprecated. Did you read the link you provided? It says to use XML::LibXML which I do. => "XML::LibXML::Simple - XML::LibXML clone of XML::Simple::XMLin()" My code demo does use warnings. "-w is the older version of the use warnings pragma, which is preferred nowadays. While -w is global, use warnings is lexical, and can be activated selectively." (http://stackoverflow.com/questions/12554179/difference-between-perl-and-perl-w) It appears that non-unique IDs are allowed. If you want uniqueness you declare it with something like "<xs:unique>". If this is true then XML::LibXML::Simple overriding the hash value where the key is the "id" in the output is a bug. cheers david
CC: ;
Subject: Re: [rt.cpan.org #114021] dataloss with non-unique id attr
Date: Wed, 4 May 2016 10:53:33 +0200
To: David Schmidt via RT <bug-XML-LibXML-Simple [...] rt.cpan.org>
From: Mark Overmeer <solutions [...] overmeer.net>
* David Schmidt via RT (bug-XML-LibXML-Simple@rt.cpan.org) [160504 08:18]: Show quoted text
> Queue: XML-LibXML-Simple > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=114021 > >
> > > As you can see in the attached example the first item is "overriden" > > > without any warning. I am not saying that XML::LibXML::Simple is > > > wrong here, but I dont know enough about XML to figure out where > > > the error lies.
(I'm just back after holidays) Show quoted text
> > $ perl -w test.pl > > <item> element has non-unique value in 'id' key attribute: id-123 at > > /usr/perl5.22.1sp/lib/site_perl/5.22.1/XML/LibXML/Simple.pm line 463. > > $VAR1 = { > > 'result' => { > > 'item' => { > > 'id-123' => { > > 'content' => 'b' > > } > > } > > } > > }; > > > > Anyway, I wonder if this module should be marked as "discouraged". > > After all it's a clone if XML::Simple, and that module has in the > > meantime this notice: > > https://metacpan.org/pod/XML::Simple#STATUS-OF-THIS-MODULE
>
Show quoted text
> I am using XML::LibXML::Simple, this module is not deprecated. [...]
"discouraged" is not an alias of "deprecated". Yes, it is much, much preferred to process XML with a schema: in that case, you can optimize the Perl representation of the XML data in a predictable way. XML::Simple is a module with a (too?) high level of dwimmery, in the Perl tradition. And that makes it easy to shoot yourself in your foot using it. The manual is long, and you must read most of it to understand all foot-angles. Dwimmery, on the other hand, also shows what people needed as functionality of time. XML::LibXML::Simple attempts to be bugwards compatible with that interface. You are hurt by the default use of KeyAttr, which automatically converts items with attributes 'name', 'key', or 'id' into HASHes. This is a good guess in the common sense. For instance, the 'id' attribute is nearly always of ID-type as defined in W3C-schema's, which are required to be unique for the document. So: the easy work-around for you is to change the KeyAttr list. That's not a bug: it is described in the manual and follows common practice in the real world. Show quoted text
> My code demo does use warnings. > "-w is the older version of the use warnings pragma, > which is preferred nowadays. While -w is global, use > warnings is lexical, and can be activated selectively."
Yes, I never use '-w' myself. XML::LibXML::Simple started with a pure code copy of XML::Simple, but rewriting the DOM handling. The original module used "warn '...' if $^W" a lot, where $^W is directly related to the '-w' command-line flag, not to 'no warnings'. I am considering now replacing the use of $^W for a clean warning class. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Will not change the interface wrt XML::Simple