Closed roryzweistra closed 3 years ago
Sorry but I can't reproduce:
$ perl -e 'use XML::Hash::XS;use Data::Dumper;print Dumper xml2hash("test.txt")'
'GuestCharges' => {
'GuestCharge' => [
{
'PersonType' => 'C',
'Amount' => '0',
'MaxAge' => '11',
'Type' => 'ExtraDay',
'MinCount' => '1',
'End' => '2021-12-31',
'Duration' => 'P1D',
'MaxCount' => '1',
'AddToBaseCharge' => 'false',
'Board' => '2',
'MinAge' => '2',
'Start' => '2021-01-03'
},
{
'Type' => 'ExtraDay',
'MaxAge' => '11',
'Amount' => '0',
'PersonType' => 'C',
'End' => '2021-12-31',
'MinCount' => '1',
'AddToBaseCharge' => 'false',
'MaxCount' => '1',
'Duration' => 'P1D',
'Start' => '2021-01-03',
'MinAge' => '2',
'Board' => '4'
},
{
'MaxCount' => '1',
'Duration' => 'P1D',
'AddToBaseCharge' => 'false',
'Start' => '2021-01-03',
'MinAge' => '2',
'Board' => '5',
'PersonType' => 'C',
'Amount' => '0',
'MaxAge' => '11',
'Type' => 'ExtraDay',
'MinCount' => '1',
'End' => '2021-12-31'
},
{
'MaxAge' => '11',
'Type' => 'ExtraDay',
'PersonType' => 'C',
'Amount' => '0',
'End' => '2021-12-31',
'MinCount' => '1',
'AddToBaseCharge' => 'false',
'Duration' => 'P1D',
'MaxCount' => '1',
'Board' => '1',
'Start' => '2021-01-03',
'MinAge' => '2'
}
]
},
Please tell me which version of the module, which operating system and example code of use.
Thanks for your quick reply, I've narrowed it down to passing a filehandle.
This breaks the hash
use XML::Hash::XS;
use Data::Dumper;
open ( my $fh, "<", "test.txt" ) or die "Can't open file 'test.txt'";
my $conv = XML::Hash::XS->new();
my $hash = $conv->xml2hash( $fh );
print Dumper $hash;
This works!
use XML::Hash::XS;
use Data::Dumper;
my $conv = XML::Hash::XS->new();
my $hash = $conv->xml2hash( "test.txt" );
print Dumper $hash;
I can work around it now, but to my understanding passing a filehandle should work right?
This bug is reproduced for me and it is related specifically with parsing the file handle I have already fixed it in the new version, please check.
Thanks for report.
Yes updated version works! Thanks for the quick fix.
I have unexpected results parsing the attached test.xml
The parsing process seems to miss a closing quote or something. My hash comes out as:
On the second GuestCharge I expect the MaxAge property to be INT 11 instead of string:
Using XML::Simple's XMLIN doesn't break on the MaxAge property.
It could be something in the xml file that I have missed but it looks valid to me. Checked for hidden characters too. Any ideas what's going on? I have this problem on both a debian machine and a Mac.
test.txt
Thanks!
Rory