You're on the right track. I've never used XML::SAX::ByRecord, but I used the technique you describe extensively while building XML:Validator::Schema. Usually it's a simple matter of keeping a stack of data in your filter object. So when you see a category you do:

my $category_stack = $self->{category_stack} ||= []; push @$category_stack, { some => $category, data => $here };

Then when you see a title and you're ready to finish work on the category you just pop it off:

my $category_stack = $self->{category_stack}; my $category_data = pop @$category_stack;

Using a stack allows categories to nest. Popping off the category data means the stack is conservative and will shrink as stored data is used. You definitely want to avoid building a data structure that can contain all the category data in your file.

Does that make sense?

-sam


In reply to Re: Modifying Records with XML::SAX::ByRecord by samtregar
in thread Modifying Records with XML::SAX::ByRecord by Lorphos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.