Howdy howdy,
I like XML Twig. However in the OO perl class I am programming I have a twig and am using to parse and XML file. So I assign the handler in the twig declaration, and when I start coding the handler in this class of mine I think "Oh, wait, the handler actually belongs to the twig, which is why the first argument is the twig itself. So, there is no way I can use this handler to take values from the XML item and pass it to an array in the class for use later on!" Am I wrong? Is there a way the class using the XML::Twig can swap info with the handlers?
package SampleClass;
sub new{
my $class = shift;
my $self = {};
$self->{configFile} = shift;
$self->{fileContents} = ();
$self->{twig} = new XML::Twig(twig_handlers =>
{
tag => \&tagHandler,
});
bless $self, $class;
}
. . .
sub tagHandler{
my $twig = shift;
my $tag = shift;
my $client_name = $tag->first_child('client')->text;
my $version = $tag->first_child('version')->text;
}
So I have this handler, and I want to take that text I am getting and use it in SampleClass. Not sure how.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.