可能重複:
Why am I getting an 「Out of memory」 error with Perl's XML::Simple?如何使用Perl解析大型XML文件?
我有這樣一個XML文件:
<message>
<c1>
<rrcConnectionSetupComplete>
<rrc-TransactionIdentifier>2</rrc-TransactionIdentifier>
<criticalExtensions>
<c1>
<rrcConnectionSetupComplete-r8>
<selectedPLMN-Identity> 1 </selectedPLMN-Identity>
<dedicatedInfoNAS> 07410109014290112345671000028020000f0 </dedicatedInfoNAS>
</rrcConnectionSetupComplete-r8>
</c1>
</criticalExtensions>
</rrcConnectionSetupComplete>
</c1>
</message>
我使用這樣的Perl代碼訪問XML文件中的數據(我應該堅持這種訪問格式)
#!/usr/bin/perl
use strict;
use XML::Simple;
my $xml = new XML::Simple;
my $data = $xml->XMLin("uL-DCCH-Message.xml");
my $rrc_trans_identifier = $data->{'c1'}->{'rrcConnectionSetupComplete'}->{'rrc-TransactionIdentifier'};
print "rrc_trans_id :: $rrc_trans_identifier\n";
my $selected_plmn_id = $data->{c1}->{rrcConnectionSetupComplete}->{criticalExtensions}->{c1}->{'rrcConnectionSetupComplete-r8'}->{'selectedPLMN-Identity'};
print "plmn identity :: $selected_plmn_id\n";
my $rrc_dedicated_info_nas = $data->{c1}->{rrcConnectionSetupComplete}->{criticalExtensions}->{c1}->{'rrcConnectionSetupComplete-r8'}->{dedicatedInfoNAS};
print "dedicated info nas :: $rrc_dedicated_info_nas\n";
產生的輸出是,使用XML ::簡單工作正常對於較小的XML文件(如圖所示在上述輸出)
rrc_trans_id :: 2
plmn identity :: 1
dedicated info nas :: 07410109014290112345671000028020000f0
Perl代碼。
但是,如果XML文件很大,那麼XML :: Simple將無法處理,並顯示錯誤消息Ran out of memory
。
是否有任何其他XML解析器可以使用,以便我可以像上面所顯示的類似方式訪問XML文件中的元素?
如果還有其他解析器可用,是否可以通過遵循與XML :: Simple相同的約定來給出示例。
你已經問過這個在http://stackoverflow.com/questions/3726197/why-am-i-getting-an-out-of-memory-error-with-perls-xmlsimple - 請重新 - 讀你在那裏得到的建議。 – Ether 2010-09-17 05:41:44
但我以不明確的方式提出這個問題,這就是爲什麼我再一次詢問確切的場景 – 2010-09-17 06:00:50
所以編輯你的原始問題來澄清。不要垃圾網站。 – Ether 2010-09-17 06:30:09