所以我试图用以下格式解析一个xml文件......
<message>
<cmd id="result_data">
<result-file-header>
<path>PFMD</path>
<duration>10.56</duration>
<spectra-count>4</spectra-count>
</result-file-header>
<scan-results count="10">
<scan-result>
<spectrum-index>4</spectrum-index>
<scan-index>7</scan-index>
<time-stamp>13</time-stamp>
<tic>130e5</tic>
<start-mass>135</start-mass>
<stop-mass>500</stop-mass>
<spectrum count="3">131,45;181,54;240,2</spectrum>
</scan-result>
<scan-result>
<spectrum-index>2</spectrum-index>
<scan-index>5</scan-index>
<time-stamp>15</time-stamp>
<tic>100e5</tic>
<start-mass>100</start-mass>
<stop-mass>500</stop-mass>
<spectrum count="3">131,5;181,6;240,7</spectrum>
</scan-result>
</scan-results>
</cmd>
</message>
... 使用 Perl 将我想要的结果输出到文本文件中。
但是,我在处理带有连字符的 xml 名称时遇到了困难。
这是我正在使用的 Perl 代码
#!/usr/bin/perl-w
#example to write to text
my $file = "gapiparseddataexample1.txt";
unless(open FILE, '>'.$file) {
die "\nUnable to create $file\n";
}
use warnings;
use strict;
use XML::Simple;
use Data::Dumper;
my $values= XMLin('samplegapi.xml',KeyAttr=>"scan-result", ForceArray=>'scan-result');
print Dumper($values);
for my $data(@{$values->{scanresult}}) {
print FILE "Total Ion Count",":","\n";
print FILE $data->{tic},"\n";
}
非常感谢有关如何解决连字符(即用下划线替换它们)的任何建议。