yesitsjess has asked for the wisdom of the Perl Monks concerning the following question:
I'm using the following code:
use XML::TreeBuilder; foreach my $drug ($tree->find_by_tag_name('drug')){ my @targets = $drug->look_down ('_tag', 'targets')->look_down ('_tag', + 'target')->attr_get_i('partner'); foreach my $id (@targets){print "\t$id";} my @actions = $drug->look_down ('_tag', 'targets')->look_down ('_tag', + 'known-action')->as_text; foreach my $act (@actions){print "\t$act";} }
to read through the following XML:
<drug type="small molecule"> <name>Goserelin</name> <targets> <target partner="1"> <known-action>yes</known-action> <target partner="2"> <known-action>yes</known-action> <target partner="3"> <known-action>yes</known-action> </target>
but it will only prints the first result. How can I get it to capture all of the attributes and actions and print them out for each drug?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::TreeBuilder capture multiple attributes to array
by Jenda (Abbot) on Jul 06, 2012 at 01:20 UTC | |
by Anonymous Monk on Jul 06, 2012 at 09:17 UTC | |
|
Re: XML::TreeBuilder capture multiple attributes to array
by Anonymous Monk on Jul 05, 2012 at 13:25 UTC | |
by yesitsjess (Initiate) on Jul 05, 2012 at 13:41 UTC | |
by toolic (Bishop) on Jul 05, 2012 at 14:20 UTC | |
by yesitsjess (Initiate) on Jul 05, 2012 at 15:19 UTC | |
by Anonymous Monk on Jul 05, 2012 at 16:46 UTC |