title: How can I create the XML::Simple data structure using a Perl XML SAX parser?
body: <p><strong>Summary</strong>: I am looking a fast XML parser (most likely a wrapper around some standard SAX parser) which will produce per-record data structure 100% identical to those produced by <a href="http://search.cpan.org/dist/XML-Simple" rel="nofollow noreferrer">XML::Simple</a>.</p>
  
  <p><strong>Details</strong>:</p>
  
  <p>We have a large code infrastructure which depends on processing records one-by-one and expects the record to be a data structure in a format produced by XML::Simple since it always used XML::Simple since early Jurassic era.</p>
  
  <p>An example simple XML is:</p>
  
  <pre><code>&lt;root&gt;
      &lt;rec&gt;&lt;f1&gt;v1&lt;/f1&gt;&lt;f2&gt;v2&lt;/f2&gt;&lt;/rec&gt;
      &lt;rec&gt;&lt;f1&gt;v1b&lt;/f1&gt;&lt;f2&gt;v2b&lt;/f2&gt;&lt;/rec&gt;
      &lt;rec&gt;&lt;f1&gt;v1c&lt;/f1&gt;&lt;f2&gt;v2c&lt;/f2&gt;&lt;/rec&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>And example rough code is:</p>
  
  <pre><code>sub process_record { my ($obj, $record_hash) = @_; # do_stuff }
  my $records = XML::Simple-&gt;XMLin(@args)-&gt;{root};
  foreach my $record (@$records) { $obj-&gt;process_record($record) };
  </code></pre>
  
  <p>As everyone knows XML::Simple is, well, simple. And more importantly, it is very slow and a memory hog&mdash;due to being a DOM parser and needing to build/store 100% of data in memory. So, it's not the best tool for parsing an XML file consisting of large amount of small records record-by-record.</p>
  
  <p>However, re-writing the entire code (which consist of large amount of "process_record"-like methods) to work with standard SAX parser seems like an big task not worth the resources, even at the cost of living with XML::Simple.</p>
  
  <p>I'm looking for an existing module which will probably be based on a SAX parser (or anything fast with small memory footprint) which can be used to produce <code>$record</code> hashrefs one by one based on the XML pictured above that can be passed to <code>$obj-&gt;process_record($record)</code> and be 100% identical to what XML::Simple's hashrefs would have been.</p>
  
  <p>I don't care much what the interface of the new module is; e.g whether I need to call <code>next_record()</code> or give it a callback coderef accepting a record.</p>