我需要存储 xml 数据
<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:K11645 ko:K16305 ko:K16306" type="ortholog" reaction="rn:R01070"
link="http://www.kegg.jp/dbget-bin/www_bget?K01623+K01624+K01622+K11645+K16305+K16306">
<graphics name="K01623..." fgcolor="#000000" bgcolor="#BFBFFF"
type="rectangle" x="483" y="404" width="46" height="17"/>
</entry>
</pathway>
到数据结构中以供进一步使用。DS 喜欢哈希和数组,这是我的代码
#!/usr/bin/perl
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 ";
}
}
到目前为止,我可以访问除 Graphics 节点及其子节点之外的所有元素