I have written a log error parser using XML::Twig (of course, the logs are in XML) where the status message is at the same level as the request data. When I write a TwigHandler for the section of data that contains an error, I need to retrieve my parent's sibling (my uncle) so that I can pass the offending request along with the error. When I try to access that in my sub-routine, the elements for my parent and grandparent exist, but my parent's sibling does not. An example will be better: The XML:
<log> <msg> <error name="ID not found" /> <request name="myRequest"/> </msg> </log>
A snippet that is *like* my code:
# Begin code my $handler = { 'log/msg/error' => \&mysub }; my $twig = Twig->new( TwigRoots => { 'log/msg' => 1 }, TwigHandlers => $handler }); # The handler should only be invoked when an error exists sub mysub { my ($twig, $elt) = @_; $elt->parent()->parent()->print; $twig->purge; } #End code
The output of this is:
<log><msg><error name="ID not found" /></msg></log>
No matter what I do, I can't see the "request" that is part of the original TwigRoot. I have tried using parent()->sibling("request") and other things, such as parent->parent->next_child("request"). It appears that only the sub-elements are passed in to $twig. Good thoughts are appreciated... DrSax

In reply to XML::Twig - can't find my uncle! by DrSax

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.