Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^5: XML::Twig Help

by toolic (Bishop)
on Jan 07, 2011 at 17:19 UTC ( [id://881132]=note: print w/replies, xml ) Need Help??


in reply to Re^4: XML::Twig Help
in thread XML::Twig Help

use warnings; use strict; use XML::Twig; my $xmlstr = <<EOF; <TREES> <APPLE> <TYPE id="1001">Scarlet</TYPE> <TYPE id="1002">Red</TYPE> <TYPE id="1003">Gold</TYPE> <TYPE id="1004">Fuji</TYPE> <TYPE id="1005">Scarlet</TYPE> </APPLE> <PEAR> <TYPE id="1001">Bradford</TYPE> <TYPE id="1002">Cleveland Select</TYPE> <TYPE id="1003">Aristocrat</TYPE> <TYPE id="1004">Autumn Blaze</TYPE> </PEAR> </TREES> EOF my $twig = XML::Twig->new(twig_handlers => {APPLE => \&apple}); $twig->parse($xmlstr); sub apple { my ($t, $elt) = @_; for my $type ($elt->children('TYPE')) { print $type->att('id'), "\n"; print $type->text(), "\n"; print "\n"; } } __END__ 1001 Scarlet 1002 Red 1003 Gold 1004 Fuji 1005 Scarlet

Use warnings too.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-19 14:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found