<?xml version="1.0" encoding="windows-1252"?>
<node id="1012392" title="XML::Simple - Handling inconsistency" created="2013-01-09 02:00:29" updated="2013-01-09 02:00:29">
<type id="115">
perlquestion</type>
<author id="711414">
nagalenoj</author>
<data>
<field name="doctext">
&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt; I'm using XML::Simple to parse some xml data. I find it works inconsistently for some cases. I'm just trying to make it provide consistent style of output. But, I couldn't get it. Here is my sample program.&lt;/p&gt;
&lt;code&gt;
use strict;
use warnings;
use Data::Dumper;
use XML::Simple;


my $res = "&lt;results&gt;
                        &lt;binding name=\'description\'&gt;
                                &lt;literal xml:lang=\'en\'&gt;First article. &lt;/literal&gt;
                        &lt;/binding&gt;
        &lt;/results&gt;";

my $res2 = "&lt;results&gt;
                        &lt;binding name=\'image_url\'&gt;
                                &lt;uri&gt;Football.png&lt;/uri&gt;
                        &lt;/binding&gt;
                        &lt;binding name=\'description\'&gt;
                                &lt;literal xml:lang=\'en\'&gt;Second article.&lt;/literal&gt;
                        &lt;/binding&gt;
        &lt;/results&gt;";

my $result = XMLin($res);
my $result2 = XMLin($res2);

print Dumper $result;
print Dumper $result2;
&lt;/code&gt;
&lt;p&gt;Output it produces is,&lt;/p&gt;
&lt;code&gt;
$VAR1 = {
          'binding' =&gt; {
                       'literal' =&gt; {
                                    'content' =&gt; 'First article. ',
                                    'xml:lang' =&gt; 'en'
                                  },
                       'name' =&gt; 'description'
                     }
        };
$VAR1 = {
          'binding' =&gt; {
                       'image_url' =&gt; {
                                      'uri' =&gt; 'Football.png'
                                    },
                       'description' =&gt; {
                                        'literal' =&gt; {
                                                     'content' =&gt; 'Second article.',
                                                     'xml:lang' =&gt; 'en'
                                                   }
                                      }
                     }
        };

&lt;/code&gt;
&lt;p&gt;If you look at description tag. You could find the difference in the output it produced. I find, it works fine for 'Second article.' in the example. Is there any way to make it give the similar structure?&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;</field>
</data>
</node>
