Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Answer: Strip that XML!

( #46535=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > Strip that XML! contributed by mirod

Using XML::Twig:

use XML::Twig; my $xml = <<EOF; <xml> <email>toto@foo.com</email><name>Toto</name> <email>tata@bar.com</email><name>Tata</name> <email>tutu@baz.com</email><name>Tutu</name> </xml> EOF my @email; my @name; my $twig = new XML::Twig( TwigHandlers => { email => sub { push @email, $_[1]->text; }, # $_[1] is the element + name => sub { push @name , $_[1]->text; } } ); $twig->parse( $xml ); print "email: @email\n"; print "name: @name\n";

Comment on Answer: Strip that XML!
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2015-07-30 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls