Hi All,
I need help in parsing a xml document.
experiments total-hybs="629" total-samples="733" total="21" to="21" fr +om="1"> &#8722; <experiment accnum="E-GEOD-8918" array="Agilent Human Genome CGH M +icroarray 44B [G4410B]" biosamples-png="download/mageml/E-GEOD-8918.b +iosamples.png" biosamples-svg="download/mageml/E-GEOD-8918.biosamples +.svg" fgem="download/mageml/E-GEOD-8918.processed.zip" fgem-count="87 +" hybs="87" id="1636341195" name="CGH profiling of 87 indolent non-ho +dgkin s lymphoma (NHL)" releasedate="2008-06-19" samples="174" sdrf +="download/mageml/E-GEOD-8918.sdrf.txt" species="Homo sapiens" two-co +lumns="download/mageml/E-GEOD-8918.2columns.txt"> &#8722; <users> <user id="1"/> </users> &#8722; <secondaryaccessions> <secondaryaccession>GSE8918</secondaryaccession> </secondaryaccessions> &#8722; </experiment>
Can anyone please suggest how can I retrieve accnum in experiment. Using XML twig I could retrieve secondaryaccession.
perl script is as follow
use strict; use XML::Twig; my $t= new XML::Twig( TwigHandlers=> { experiment => \&experiment}); $t->parsefile( '/home/adi/lwp_cgh_hs.xml'); exit; sub experiment { my ($t, $experiment)= @_; my %experiment; $experiment{secondaryaccessions}= $experiment->field( 'secondaryac +cessions'); # $experiment{name}= $experiment->field( 'experimentName'); #$experiment{description}= $experiment->field( 'Description'); $experiment{secondaryaccession}= join ':', map {$_->text || ''} @{[$experiment->children( 'secondaryaccession' +)]}; print "$experiment\n"; print "$experiment{secondaryaccessions}: \n"; print " : $experiment{secondaryaccession}\n"; $experiment->delete; }
Thank you

In reply to XML parsing by advait

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.