Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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.


Comment on Re: Parsing an XML file
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-12-20 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (99 votes), past polls