shaq has asked for the wisdom of the Perl Monks concerning the following question:
I need to pars an xmlfile,using perl. So basically I want to convert this xml file to some data structure like hashes and arrays.by this code now I can have access to the all nodes except for graphics node and its elements.
XML file:
<pathway name="path:ko00010" org="ko" number="00010" title="Glycolysis / Gluconeogenesis" image="http://www.kegg.jp/kegg/pathway/ko/ko00010.png" link="http://www.kegg.jp/kegg-bin/show_pathway?ko00010"> <entry id="13" name="ko:K01623 ko:K01624 ko:K01622 ko:K16306" link="http://www.kegg.jp/dbgetbin/www_bgetK01623+K16306"> <graphics name="K01623..." fgcolor="#000000" bgcolor="#BFBFFF" type="rectangle" x="483" y="404" width="46" height="17"/> </entry> </pathway>
here is the perl code :
+ + + + use XML::LibXML; use strict; use warnings; my $parser = new XML::LibXML; my $xmlp= $parser -> parse_file("ko00010.xml"); my $rootel = $xmlp -> getDocumentElement(); my $elname = $rootel -> getName(); my @rootelements=$rootel -> getAttributes(); foreach my $rootatt(@rootelements){ my $name = $rootatt -> getName(); my $value = $rootatt -> getValue(); print " ${name}[$value]\n "; } my @kids = $rootel -> childNodes(); foreach my $child(@kids) { my $elname = $child -> getName(); my @atts = $child -> getAttributes(); foreach my $at (@atts) { my $name = $at -> getName(); my $value = $at -> getValue(); print " ${name}[$value]\n "; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing xml using libXML
by runrig (Abbot) on Jul 12, 2013 at 16:44 UTC | |
by shaq (Initiate) on Jul 18, 2013 at 11:35 UTC | |
by runrig (Abbot) on Jul 18, 2013 at 17:47 UTC | |
Re: Parsing xml using libXML
by hippo (Bishop) on Jul 12, 2013 at 13:05 UTC | |
by shaq (Initiate) on Jul 18, 2013 at 11:37 UTC | |
by hippo (Bishop) on Jul 19, 2013 at 09:44 UTC | |
Re: Parsing xml using libXML
by zork42 (Monk) on Jul 14, 2013 at 14:18 UTC | |
by Anonymous Monk on Jul 15, 2013 at 00:05 UTC | |
by zork42 (Monk) on Jul 15, 2013 at 04:14 UTC | |
by Anonymous Monk on Jul 15, 2013 at 07:38 UTC | |
by zork42 (Monk) on Jul 17, 2013 at 12:38 UTC | |
Re: Parsing xml using libXML
by Anonymous Monk on Jul 12, 2013 at 14:18 UTC | |
by shaq (Initiate) on Jul 18, 2013 at 11:38 UTC | |
by Anonymous Monk on Jul 18, 2013 at 12:01 UTC | |
by shaq (Initiate) on Jul 18, 2013 at 12:57 UTC | |
by Anonymous Monk on Jul 18, 2013 at 13:58 UTC |
Back to
Seekers of Perl Wisdom