Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: ext.Robin.Julian [...] comptel.com
Cc:
AdminCc:

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



CC: "Breitenbach Jaco" <Jaco.Breitenbach [...] comptel.com>
Subject: XMLin() mapping of an element changes when there is an attribute called "name".
Date: Thu, 12 Nov 2009 19:22:33 -0000
To: <bug-XML-Simple [...] rt.cpan.org>
From: "Consultant Julian Robin" <ext.Robin.Julian [...] comptel.com>
Hello, Below are two simple examples where I call XMLin and XMLout for a simple piece of XML. In the first example, the elements have an attribute called "name" and in the second, the attribute is called "not_name". The behaviour is different in the two cases and I could not find any documented reason for it. What I am trying to do is produce XML output that is the same as the XML input. However with the different treatment of the "name" attribute, I have not been able to do this. (I did notice that while trying to create a simple example for this defect description, that with an encoding of less nested elements, the output XML is correct in both cases). The Perl Code use strict; use XML::SAX; use XML::Simple; use Data::Dumper; my $decode = XMLin ("fred.xml", ForceArray => 1); print Dumper ($decode); my $encode = XMLout($decode, RootName => "stream", XMLDecl => 1); print $encode; exit 0; EXAMPLE 1 (FAILS IMHO): Input XML: <stream> <nodes> <node name="X"> </node> <node name="Y"> </node> </nodes> </stream> Data::Dumper Output: $VAR1 = { 'nodes' => [ { 'node' => { 'X' => {}, # This looks like I have specified "Variables =>{'name'} in the code but I have not. 'Y' => {} } } ] }; Output XML: <stream> <nodes name="node"> <X></X> <Y></Y> </nodes> </stream> EXAMPLE 2 (WORKS AS I EXPECT IT TO): Input XML: <stream> <nodes> <node not_name="X"> </node> <node not_name="Y"> </node> </nodes> </stream> Data::Dumper Output: $VAR1 = { 'nodes' => [ { 'node' => [ { 'not_name' => 'X' }, { 'not_name' => 'Y' } ] } ] }; Output XML: <stream> <nodes> <node not_name="X" /> <node not_name="Y" /> </nodes> </stream> Regards, Robin Julian. ------------------------------------------------------------------------ ------------ Robin Julian Mediation Consultant Comptel Corporation Address: Axiom Systems, 69 Suttons Business Park, Reading, RG6 1AZ Mobile: +44 75 2667 4693 Fax: +44 118 929 4001 ext.Robin.Julian@comptel.com

Message body is not shown because it is too large.

The behaviour you describe is both expected and documented. You can use the KeyAttr option to change it. In addition to the module documentation, this article may help: http://www.perlmonks.org/index.pl?node_id=218480 If your XML processing needs are non-trivial then XML::Simple may be the wrong module. If you can't get the results you want with XML::Simple in 5-10 minutes then I recommend switching to XML::LibXML. The two modules are compared here: http://www.perlmonks.org/index.pl?node_id=490846 Cheers Grant
Subject: RE: [rt.cpan.org #51478] XMLin() mapping of an element changes when there is an attribute called "name".
Date: Fri, 13 Nov 2009 11:20:59 -0000
To: <bug-XML-Simple [...] rt.cpan.org>
From: "Consultant Julian Robin" <ext.Robin.Julian [...] comptel.com>
Hi Grant, Thanks very much for your fast and detailed response. I will switch over to XML::LibXML. I think you've saved me a lot of time. Regards, Robin. Show quoted text
-----Original Message----- From: Grant McLean via RT [mailto:bug-XML-Simple@rt.cpan.org] Sent: 12 November 2009 19:58 To: Consultant Julian Robin Subject: [rt.cpan.org #51478] XMLin() mapping of an element changes when there is an attribute called "name". <URL: https://rt.cpan.org/Ticket/Display.html?id=51478 > The behaviour you describe is both expected and documented. You can use the KeyAttr option to change it. In addition to the module documentation, this article may help: http://www.perlmonks.org/index.pl?node_id=218480 If your XML processing needs are non-trivial then XML::Simple may be the wrong module. If you can't get the results you want with XML::Simple in 5-10 minutes then I recommend switching to XML::LibXML. The two modules are compared here: http://www.perlmonks.org/index.pl?node_id=490846 Cheers Grant