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

Re: Parsing an XML file

by aitap (Deacon)
on Aug 24, 2012 at 12:16 UTC ( #989509=note: print w/replies, xml ) Need Help??

in reply to Parsing an XML file

Consider using XML::Twig, which can parse large files without consuming a lot of memory:
#!/usr/bin/perl use warnings; use strict; use XML::Twig; use feature 'say'; my $parser = XML::Twig::->new( twig_handlers => { '/pathway/reaction[@name=~/^rn:/]' => \&handle, # use XPath to describe what you want to handle } ); $parser->parsefile("myfile"); sub handle { my($twig, $elt) = @_; # handlers are given an XML::Twig object and an XML::Twig::Elt + object say $elt->att("name"); say " substrate[s]: ", map { $_->att("id")." " } $elt->children("s +ubstrate"); say " product[s]: ", map { $_->att("id")." " } $elt->children("pro +duct"); }
Sorry if my advice was wrong.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989509]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (12)
As of 2017-07-25 12:54 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (370 votes). Check out past polls.