title: Perl, XML::Twig, how to reading field with the same tag
body: <p>I'm working on processing a XML file I receive from a partner. I do not have any influence on changing the makeup of this xml file. An extract of the XML is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;objects&gt;
    &lt;object&gt;
      &lt;id&gt;VW-XJC9&lt;/id&gt;
      &lt;name&gt;Name&lt;/name&gt;
      &lt;type&gt;House&lt;/type&gt;
      &lt;description&gt;
      &lt;![CDATA[&lt;p&gt;some descrioption of the house&lt;/p&gt;]]&gt; &lt;/description&gt;
      &lt;localcosts&gt;
        &lt;localcost&gt;
          &lt;type&gt;mandatory&lt;/type&gt;
          &lt;name&gt;What kind of cost&lt;/name&gt;
          &lt;description&gt;
            &lt;![CDATA[Some text again, different than the first tag]]&gt;
          &lt;/description&gt;
        &lt;/localcost&gt;
      &lt;/localcosts&gt;
    &lt;/object&gt;
  &lt;/objects&gt;
  </code></pre>
  
  <p>The reason I use Twig is that this XML is about 11GB big, about 100000 different objects) . The problem is when I reach the localcosts part, the 3 fields (type, name and description) are skipped, probably because these names are already used before.</p>
  
  <p>The code I use to go through the xml file is as follows:</p>
  
  <pre><code>my $twig= new XML::Twig( twig_handlers =&gt; { 
                   id                            =&gt; \&amp;get_ID,
                   name                          =&gt; \&amp;get_Name,
                   type                          =&gt; \&amp;get_Type,
                   description                   =&gt; \&amp;get_Description,
                   localcosts                    =&gt; \&amp;get_Localcosts
  });
  
  $lokaal="c:\\temp\\data3.xml";
  getstore($xml, $lokaal);
  $twig-&gt;parsefile("$lokaal");
  
  sub get_ID          { my( $twig, $data)= @_;  $field[0]=$data-&gt;text; $twig-&gt;purge; } 
  sub get_Name        { my( $twig, $data)= @_;  $field[1]=$data-&gt;text; $twig-&gt;purge; }
  sub get_Type        { my( $twig, $data)= @_;  $field[3]=$data-&gt;text; $twig-&gt;purge; }
  sub get_Description { my( $twig, $data)= @_;  $field[8]=$data-&gt;text; $twig-&gt;purge; }
  sub get_Localcosts{
  
    my ($t, $item) = @_;
  
    my @localcosts = $item-&gt;children;
    for my $localcost ( @localcosts ) {
      print "$field[0]: $localcost-&gt;text\n";
      my @costs = $localcost-&gt;children;
      for my $cost (@costs) {
        $Type       =$cost-&gt;text if $cost-&gt;name eq q{type};
        $Name       =$cost-&gt;text if $cost-&gt;name eq q{name};
        $Description=$cost-&gt;text if $cost-&gt;name eq q{description};
        print "Fields: $Type, $Name, $Description\n";
      }
    }
    $t-&gt;purge;    
  }
  </code></pre>
  
  <p>when I run this code, the main fields are read without issues, but when the code arrives at the 'localcosts' part, the second for-next loop is not executed. When I change the field names in the xml to  unique ones, this code works perfectly.</p>
  
  <p>Can someone help me out?</p>
  
  <p>Thanks</p>