Passing data to XML::Twig twig_roots callbacks....?
Dustin Suchter <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
I'm having a hard time wrapping my brain around the idea of using
twig_roots with twig_handlers (specifically so I can pass data back
and forth) in order to process large XML files. Perhaps I'm missing
something obvious, and hopefully someone can help!
I've got a large XML file currently parsed cleanly using twig_roots
and setting callbacks on various elements:
my $xmltwigobj = XML::Twig->new(
twig_roots => {
'Information/Child/Grandchild' => \&get_grandchild_info,
}
);
sub get_grandchild_info {
my ($twig, $element) = @_;
#blah blah, do something print-y here
}
My problem is that I'd like to store the info I parse via
get_grandchild_info somewhere useful, where “useful” is not (a) in a
global or (b) printed somewhere. Specifically, I'd like to pass the
reference to a DBM::Deep object to get_grandchild_info and have any
new info added to the existing DBM::Deep object, but really we
shouldn't need to be specific, I just want something like:
sub get_grandchild_info_extra {
my ($twig, $element, $hash_ref) = @_;
#awesomeness
}
I found Question 27 at
http://xmltwig.com/xmltwig/XML-Twig-FAQ.html#Q27 to be pretty spot-on
for my needs in terms of data passing, but in the end it didn't help
me since nobody seems to use the twig_roots parsing methodology in
combination with the 'closures' mentioned there (which smell a lot
like globals to me anyway...).
I'd love to see an example of how to modify my code, above, to allow
me to pass a 3rd argument to my callback subroutine.
thanks,
-d
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs