<?xml version="1.0" encoding="windows-1252"?>
<node id="1012407" title="Re: XML::Simple - Handling inconsistency" created="2013-01-09 04:00:53" updated="2013-01-09 04:00:53">
<type id="11">
note</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
&lt;p&gt;&lt;i&gt;Is there any way to make it give the similar structure?&lt;/i&gt;&lt;p&gt; use [mod://XML::Rules] , just give xml2XMLRules the most complex detailed xml file you have, and you'll get rules/data like these
&lt;c&gt;#!/usr/bin/perl --
use strict; use warnings;
use Data::Dump;
use XML::Rules;
my $ta = XML::Rules-&gt;new(
    qw/ stripspaces 8 /,
    rules =&gt; 
    {
      'literal' =&gt; 'as is',
      'binding' =&gt; 'as array no content',
      'uri' =&gt; 'content',
      'results' =&gt; 'no content'
    }
);
my @xml = (
q{&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;
},
q{&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;
}
);

dd( my$ref = $ta-&gt;parsefile( \$_ )) for @xml;

__END__
{
  results =&gt; {
    binding =&gt; [
      { name =&gt; "image_url", uri =&gt; "Football.png" },
      {
        literal =&gt; { "_content" =&gt; "Second article.", "xml:lang" =&gt; "en" },
        name =&gt; "description",
      },
    ],
  },
}
{
  results =&gt; {
    binding =&gt; [
      {
        literal =&gt; { "_content" =&gt; "First article.", "xml:lang" =&gt; "en" },
        name =&gt; "description",
      },
    ],
  },
}
&lt;/c&gt;
&lt;p&gt; Sure, you could get there with XML::Simple, but I don't bother anymore
&lt;p&gt;[mod://Data::Diver] for navigation :)</field>
<field name="root_node">
1012392</field>
<field name="parent_node">
1012392</field>
<field name="reputation">
16</field>
</data>
</node>
