For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2005 > XML::Twig









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author XML::Twig
Peter Rabbitson

2005-03-20, 3:57 pm

Here goes my next question (I apologize for being such a nag). After
extensive reading on XML processing technologies I figured for my
application of XML files with hundreds of same-level branches XML::Twig is
the answer. Note that I do not do *any* XML output - I am just and only
processing interesting data from premade XML files, thus I am interested in
the simplest and least resource expensive approach. I got the thing to work
and all, indeed the memory footprint is a little smaller than with
XML::Simple (not by much though, I still waste xml_size*4 memory while
processing). The bigger question is why the code:

my $objinfo_parser = XML::Twig->new (
twig_handlers => { 'Product' => \&product_handler },
twig_roots => { 'Products/Product' => 1 }
);

$objinfo_parser->parseurl ('http://www.3btech.net/3btech/objinfo.xml');


sub product_handler {

my ($twig, $child) = @_;

print ' * ';

$twig->purge;
}


Produces all * after everything is processed, instead of printing them one
by one once every product tag closes? From what I understood it crawls
through an XML linearly (that's the only way anyway), and once it encounters
an opening tag for anything that matches twig_roots it starts recording,
once it sees the closing tag it has a complete sub-branch (twig), gives it
to the corresponding handler, the handler purges it at the end of the sub
and everything starts over again... However this is obviously not happening.

Thanks for the input

Peter
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com