Thanks for the reply and for the pointer to path(). I ran a few tests and I think I could make that work.

Is this really the best way to approach this problem, though? I am not trying to be argumentative; I am just a little surprised because it was not what I was expecting.

This approach requires that I write a lot of

if( $child_of_some_element ) { # do this } elsif( $child_of_some_other_element ) { # do something else }
in several different handlers, which seems pretty high maintenance - if the structure of a Class element (for example) changes I have to make sure all of the handlers are changed appropriately.

I was hoping there would be a way to approach this that is a little more OO-like, where the child element wouldn't have to know what the parent element was in order to do the Right Thing. Ideally, I'd like to think about parsing this file in chunks: parse Class elements this way, parse Attribute elements that way, etc, and each chunk (think "object") could have its own TaggedValue handler (for example).

Perhaps I am thinking about this in the wrong way and over-complicating matters, or my expectation for how to solve this problem is a Bad Idea.

Thoughts?


In reply to Re^2: Creating context-specific handlers in XML::Twig by bobf
in thread Creating context-specific handlers in XML::Twig by bobf

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.