Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Easily XML filtering?

by GrandFather (Sage)
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

Replies are listed 'Best First'.
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?
[Discipulus]: my warmest comprehension karlgoethebier ;=(
[Discipulus]: yes LanX.. is so good to be appreciated (I fortunately have a big self estimation that compensate)
[LanX]: you can manipulate a html tree by addressing and replacing so called document objects (DOM) and from my experience the same methods can be used with any XML, though I didn't test all browsers yet
LanX just joking, playing "ego judo"
[marto]: good morning all
[Corion]: Hi marto!
[marto]: the race to the bottom continues, many people lost their job yesterday as a client moves to another outsourcer
[LanX]: brexit or perlxit ?
[Corion]: Ow, marto :-/ I hope you aren't affected (except for the looming dread of more work for the same pay)
[marto]: unrelated

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2017-03-23 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (285 votes). Check out past polls.