I'm scratching my head over this and hope you can point out the mistake I'm making here. Essentially I'm trying to parse a very large XML file (~600Mb) chunk-by-chunk using XML::Twig and trying to extract relevant information. I find that I cannot get value of an attribute inside an element using findvalue. XML snippet and code below. Thanks for your help!
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ReleaseSet Dated="2014-02-11" Type="full"> <ClinVarSet ID="176987"> <RecordStatus>current</RecordStatus> <Title>Single allele AND Benign familial neonatal seizures 1</Title> <ReferenceClinVarAssertion> <ClinVarAccession Acc="RCV000020962" Version="1" Type="RCV" DateUp +dated="2013-05-06"/> </ReferenceClinVarAssertion> </ClinVarSet> </ReleaseSet>
And the perl bit
#!/usr/bin/perl use strict; use warnings; use XML::Twig; use Data::Dumper; my $twig= XML::Twig::XPath->new( twig_handlers => { ClinVarSet => \&ClinVar }, pretty_print => 'indented' ); $twig->parsefile($file); $twig->dispose; sub ClinVar { my( $twig, $Clin)= @_; my $ClinVarSetID = $Clin->{'att'}->{'ID'}; my $status = $Clin->first_child('RecordStatus')->text; my $Accession = $Clin->findvalue('./ReferenceClinVarAssertion/ClinVa +rAccession[@Acc]'); print "ID: $ClinVarSetID\tStatus: $status\tAccession: $Accession\n"; }
I get the first two values $ClinVarSetID and $status but I cannot get the value of the attribute 'Acc' using the XPath
In reply to Using findvalue in XML::Twig::XPath by jswamin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |