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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.