kejv2 has asked for the wisdom of the Perl Monks concerning the following question:
Hello all,
I am parsing a xml file using XML::Twig like this:
XML::Twig->new( twig_roots => { 'div' => \&div } )->parsefile("my_file"); sub div { my ($t, $elt) = @_; # do something return 1; }
I have a run-time parameter which I want to get in div (or any other) element handler. How can I do this?
I would expect something like putting this parameter into XML::Twig constructor and then getting it from twig $t element. But there is nothing like this described in the documentation. The only way I can think about is to define own element handling package with method returning my parameter and putting this package as elt_class option into XML::Twig constructor. But that seems terribly artificial to me.
Any better ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Twig - provide additional parameters to twig_roots handlers
by remiah (Hermit) on Sep 30, 2012 at 20:40 UTC | |
|
Re: XML::Twig - provide additional parameters to twig_roots handlers
by Jenda (Abbot) on Oct 01, 2012 at 07:11 UTC | |
by kejv2 (Acolyte) on Oct 01, 2012 at 19:29 UTC | |
by Jenda (Abbot) on Oct 01, 2012 at 22:16 UTC | |
by mirod (Canon) on Oct 03, 2012 at 12:34 UTC | |
by Jenda (Abbot) on Oct 03, 2012 at 19:00 UTC | |
by Anonymous Monk on Oct 03, 2012 at 15:18 UTC | |
by Anonymous Monk on Oct 03, 2012 at 15:11 UTC |