http://www.perlmonks.org?node_id=1012404


in reply to XML::Simple - Handling inconsistency

Is it helpful for you ?

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use XML::Simple; my $res = "<results> <binding name=\'image_url\'> <uri>Football.png</uri> </binding> <binding name=\'description\'> <literal xml:lang=\'en\'>First article. </literal> </binding> </results>"; my $res2 = "<results> <binding name=\'description\'> <literal xml:lang=\'en\'>Second article.</literal> </binding> </results>"; my $xml_simple = XML::Simple->new( KeepRoot => 1, KeyAttr => 1, ForceA +rray => 1 ); my $result = $xml_simple->XMLin($res); my $result2 = $xml_simple->XMLin($res2); print Dumper $result; print Dumper $result2;
Update:

Adding the output,

$VAR1 = { 'results' => [ { 'binding' => [ { 'name' => 'image_url', 'uri' => [ 'Football.png' ] }, { 'literal' => [ { 'content' => 'F +irst article. ', 'xml:lang' => ' +en' } ], 'name' => 'description' } ] } ] }; $VAR1 = { 'results' => [ { 'binding' => [ { 'literal' => [ { 'content' => 'S +econd article.', 'xml:lang' => ' +en' } ], 'name' => 'description' } ] } ] };