Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

TwigHandlers not always called?

by BenHopkins (Sexton)
on Jul 12, 2013 at 01:20 UTC ( [id://1043847]=perlquestion: print w/replies, xml ) Need Help??

BenHopkins has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks (whether ye be Monker, Monked, or Monkee):

I'm sestting up TwigHandlers like this (partial code):

my $twig = new XML::Twig( TwigHandlers => { 'byline' => \&byline, 'body.head/hedline' => \&hedline, 'body.content/p' => \&process_p, 'body.content/hl2' => \&process_body_hl2, 'body.content/block/p' => \&process_p, 'body.content/block/hl2' => \&process_body_hl2, 'body.content/table' => \&process_table, etc. etc.
... and process_body_hl2 is pretty simple:
sub process_body_hl2 { my ($t, $hl2) = @_; my $para = crunch($hl2->text); $body .= "<p><b>$para</b></p>"; }
Input looks like this:
<body.content> <hl2 style="section_head">SECTION HEAD</hl2> <hl2 style="subhead">subhead</hl2> <p/>
The output for that part comes out like this (this is a different format of xml from the input):
<body.content> <p>SECTION HEAD</p><p>subhead</p>
Where are the <b> tags? Later, the next hl2 in the body looks like this:
<p/> <hl2 style="subhead">2nd subhead</hl2>
And this one comes out the way it should:
<p><b>2nd subhead</b></p><p>
Now, how come the first two did not work, but the subsequent one did?

Replies are listed 'Best First'.
Re: TwigHandlers not always called?
by mirod (Canon) on Jul 12, 2013 at 05:10 UTC

    I don't see anything obvious at first glance, so we'll need to dig a little further.

    Could you provide a test case that we could run? It would be best if it includes the smallest code that triggers the problem, input data and expected output. This way we can reproduce the problem, and see if we can fix it (actually my real hope is that while creating the test case you figure out what the problem is, it has happened to me more than once ;--)

      Oops. Why there's a bullet in my foot! AND there's a gun in my hand! Sorry to bother you, I did it to myself. Found the problem by trying to boil down a big, complicated program into the small test cases you requested, so I guess you did help fix the problem, even though it was not caused by you.

      XML::Twig is robust and dependable.

        Glad I could help ;--)

        There are (still!) bugs in XML::Twig though, not to mention quirks that are worth asking about. So don't feel bad about asking for help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1043847]
Approved by hdb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-25 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found