in reply to example for parseing xml with xml::twig
With small files (say, < 100MB) , I usually just load the whole thing in, and then get all the elements I'm interested in, and work on them - I find it easier than the stream interface. However, in your case, we might be stretching it unless you've got a 64-bit perl. So here's a stream example. Note that for your example, I just put the whole thing in "<something>..</something>" tags so it'd be valid XML.
use strict; use warnings; use XML::Twig; my $twig = XML::Twig->new( twig_handlers => { offer => sub { printf("%s,%s,%s\n", $_->att('id'), $_->first_child('f1')->text() +, $_->first_child('f2')->text() +, ); } } ); $twig->parsefile('a.xml');
Hope that helps
|
|---|