Angharad has asked for the wisdom of the Perl Monks concerning the following question:
So far, I've managed to print out the 'residue_index' and 'residue_name' info from within the 'residue' tag. But I need to expand upon that and only print this information for 'feature_one' and not for 'feature_two'- at the moment its printing the information regardless of what feature 'residue_name' and 'residue_index' is in.<sas_residue_annotation xmlns="http://url/Schema" xmlns:xsi="http://ww +w.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://url/Sche +ma test.xsd"> <features> <feature> <feature_name>feature_one</feature_name> <residues> <residue> <residue_index>2</residue_index> <residue_name>R</residue_name> </residue> <residue> <residue_index>4</residue_index> <residue_name>V</residue_name> </residue> </residues> </feature> <feature> <feature_name>feature_two</feature_name> <residues> <residue> <residue_index>5</residue_index> <residue_name>S</residue_name> </residue> </residues> </feature> </features>
Any advice as to how I may achieve this much appreciated.
Code thus far:
#!/usr/bin/perl # use module use Data::Dumper; use strict; use warnings; use XML::Twig; my $file = shift; my $twig= new XML::Twig( twig_handlers => { residue => \&residue } ); $twig->parsefile($file); sub residue { my ($twig, $res) = @_; my $res_idx = $res->first_child('residue_index')->text; my $res_name = $res->first_child('residue_name')->text; print "$res_idx $res_name\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help on how to get information from XML file using XML::Twig requested
by toolic (Bishop) on Aug 10, 2009 at 13:10 UTC | |
|
Re: help on how to get information from XML file using XML::Twig requested
by Jenda (Abbot) on Aug 10, 2009 at 14:07 UTC |