gregaryh has asked for the wisdom of the Perl Monks concerning the following question:
This one is baffling me. I have an XML document I am trying to process with XML::Twig and I am getting an error where I think it should not.
Here is the setup:<document> <record> <attachment>data</attachment> </record> </document>
my $twig = XML::Twig->new(twig_handlers=>{record => \&process_record, attachment => \&process_attachment});
$twig->parse($xml);
sub process_attachment() { my ($twig, $attach) = @_; do some data processing .... $attach->purge; } sub process_record() { my ($twig, $record) = @_; do some data processing .... $record->purge; }
This produces an error: Can't locate object method "purge" via package "XML::Twig::Elt" at <line number>
Where line number points to $attach->purge;but in the examples given in the perldoc: "You can also purge it if you don't need to output it (if you are just extracting some data from the document for example). The handler will be called again once the next relevant element has been parsed."
$attach->flush does seem to work but I don't want to print it, so why doesn't $attach->purge work?
If I use $twig->purge it kills the whole record, not just the attachment.
The problem I am trying to address is that a record in the xml can have several very large attachments. I want to parse each attachment (loading it into an array) and then purge the xml of just the attachment from memory, leaving the rest of the record in tact until it can be processed by its handler.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: broken twig?
by mirod (Canon) on Sep 13, 2005 at 19:28 UTC | |
by gregaryh (Novice) on Sep 13, 2005 at 20:51 UTC | |
by mirod (Canon) on Sep 13, 2005 at 21:04 UTC | |
by gregaryh (Novice) on Sep 13, 2005 at 21:31 UTC | |
by mirod (Canon) on Sep 13, 2005 at 21:50 UTC | |
|
Re: broken twig?
by japhy (Canon) on Sep 13, 2005 at 19:29 UTC |