Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Easily XML filtering?

by GrandFather (Cardinal)
on May 06, 2008 at 22:48 UTC ( #685087=note: print w/ replies, xml ) Need Help??


in reply to Easily XML filtering?

Set up twig handlers for them. Consider:

use strict; use warnings; use XML::Twig; my $xml = <<XML; <companies> <Acme>Acme</Acme> <Missing>Missing</Missing> <Wobbler>Wobbler</Wobbler> <Trump>Trump</Trump> <Tibble>Tibble</Tibble> </companies> XML my @companyList = qw(Acme Wobbler Tibble); my %handlers = map {$_ => \&HandleCompany} @companyList; my $twig = XML::Twig->new (twig_handlers => \%handlers); $twig->parse ($xml); sub HandleCompany { print $_->text (), "\n"; }

Prints:

Acme Wobbler Tibble

Perl is environmentally friendly - it saves trees


Comment on Re: Easily XML filtering?
Select or Download Code
Re^2: Easily XML filtering?
by mattr (Curate) on May 07, 2008 at 18:10 UTC
    Thank you very much, I'll study Twig too for sure.

    Matt

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://685087]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2014-09-17 23:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (101 votes), past polls